1.0.4 • Published 1 year ago

@teamteanpm2024/nihil-inventore-repellat v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

yaml-configurator

Read simple YAML configs from well-known locations

Motivation

Most JS micro-services require a configuration. This package unifies this common task by providing a standard interface for loading configurations from well-known locations.

Getting started

npm i @teamteanpm2024/nihil-inventore-repellat

In the index module:

import * as Config from "@teamteanpm2024/nihil-inventore-repellat";

// load from the first location that matches.
const cfg = await Config.readConfig(
        [
            "/etc/app/config.yaml",
            "./config.yaml", 
            "./tools/config.yaml"
        ]
    );

Usage

This package provides a single interface function readConfig(). This function has three parameters:

  • Sources files
  • Required configuration keys
  • Default values

This allows to ensure complete and valid configurations before a service starts.

Source files can be a single file name or a list of locations where to expect the configuration files. If no source file is provided or none of the provided sources can be found an empty configuration is returned (see default values). If more than one source location is provided, these file locations must be presented as an Array. In this case the function will load the configuration from the first matching locations.

Required configuration keys provide the means to validate a configuration. Currently, validation is limited to check the presence of a key in the configuration. Such keys must be present anywhere in the configuration. By default this is an empty list. If the required keys are not present after merging the configuration with the default values, then the function throws an error with the message missing configuration for key: YOUR_REQUIRED_KEY.

In order to verify for deeply nested keys, the path to the key needs to be made explicit in a dot-concatenated list of keys. For example we have the following content of the file /etc/app/config.yaml:

foo:
  bar: Hello World

The following code verifies that the bar-property in the foo-category is set.

await Config.readConfig("/etc/app/config.yaml", ["foo.bar"]);

If any key in this chain is an array, then readConfig() will ckeck if the key is set at least once in one object in that array. Let's expand the above example to illustrate this behavior.

foo:
  - baz: some other configuration
  - bar: Hello World

The code will still return the configuration as the second object in the list satisfies the following verification chain.

await Config.readConfig("/etc/app/config.yaml", ["foo.bar"]);

If any key in the verification chain is missing readConfig() adds the failing chain to the error message.

If any parent object in a verification chain is missing the following error is thrown: missing configuration object for key: YOUR_REQUIRED_KEY (in YOUR.VERIFICATION.CHAIN).

Default values provides the default values for the configuration. These values are set to the configuration only if these values are not present in the loaded configuration. Like the required configuration keys, this mechanism allows default values only at the top level of the configuration.

A typical use case for using keys are credentials. In this case, the required secret information is linked to specific keys that are set to be required. All other keys can be set with defaults. If the secrets are not present in the configuration the function readConfig() will fail with an error.

PushhasOwnbootstrap cssequalmkdirpwalkECMAScript 2017shamcallbindobjectprivateFunction.prototype.namerapidECMAScript 2021valueentriespropopensnested cssvariables in cssgetoptES2019jsdomaccessibilitySymbol.toStringTagwebpromisesregular expressioninvariantless cssbyteLengthstyleguidexdgMappackagetsplugines2016settingsfindupiteratorremoveReactiveXwaapienvfseventsFloat64ArraytypeofvisualescapeWebSocketlazymake dirRegExp.prototype.flagskeysfpchaiwatchingkeyloggerObject.entriestypesafesigtermStreamdebugiterateexpressionpopmotionajvMicrosoftestree-0functionalexpresssyntaxspawnsetter3djasmineargswordbreaklinuxshelldefinePropertystyled-componentsauthbyteOffsetbluebirdbrowserajaxArrayBuffer#sliceObject.fromEntriescircularclass-validatorstreamdiffReactiveExtensionsjsonomitstatussuperstructdirESnextcorsconsttrimStartbufferYAMLrm -rftape6to5zodimportresolveArraygetPrototypeOfjson-schema-validationprunecall-boundlinewrapcomputed-typesless.jsmatchArray.prototype.findLastIndexterminalargumentses8ECMAScript 7.envuptostringtagansiframerconfigurabledataViewcharacterscolourstylescsslistenerswalkingtexttermuser-streamses-abstractwidthfindLastIndexflatworkspace:*extensionserializationgetOwnPropertyDescriptorfull-widthmkdirsqsconcatidlelanguageECMAScript 2016ES2020sliceECMAScript 2018duplexmacosdebuggerjsonpathharmonypassword@@toStringTagreact posekarmagradients csstriminternalirqposejestcjklogginges2015awesomesaucecore-jseveryjsxmime-dbpersistentpropertiesratelimitES2022RFC-6455deepvalidaccessorreadpreserve-symlinksfastcloneECMAScript 2015configschemewrapprettychineseregular expressionsmixinshigher-orderlessvaluesdeepclonees-shimsspeedforEachArrayBuffer.prototype.sliceidreact animationa11ypromiseponyfillES2015collectionurlcallappmergeecmascriptES6faststablePromiseutilitiesratetoobjectfixed-widthconsoletypedarrayArray.prototype.flatworkereslintpluginflagsbabel-corecompilernpmtypestylingtypesString.prototype.trimES2016Array.prototype.findLastURLSearchParamstypeerrorRxmonorepointerruptsexit-codebytebcryptRegExp#flagsStreamsassertionhasString.prototype.matchAllcolorssanitizethrottlefromeventseditorsortincludestyped array__proto__descriptionencryptiondefaultobjsortedURLparentsdataviewbrowserlistCSSStyleDeclarationformprivate dataObject.getPrototypeOfslotpositivehelpersindicatormoduleparsetypedarrayscompareimmerclassesfilepurestringifierstyleiteration[[Prototype]]command-lineformsclassnameurlsjapaneseECMAScript 5Setlogcollection.es6ES2023symbolsboundfind-upteststructuredClonecreateFloat32Arrayxtermgdpr$.extendauthenticationsameValueZerosuperagentqueuegenericsprotocol-buffersperformanceReflect.getPrototypeOfshebangAsyncIteratorramdarobustjQueryfulltypescriptECMAScript 3toolkit0unicodequotemulti-packageschemaeast-asian-widthcodesargumentHyBisafestringreduxtc39directoryisConcatSpreadableerrorinternal slottoSortedsanitizationtranspilereact-testing-libraryminimaltrimLeftcallbacktacitiereusearktypefoldernoperedux-toolkitmomentascii256inputlibphonenumberemojipushapipreprocessorenvironmentgetdeepcopysomefetchsyntaxerrorarraysintrinsicjson-schema-validatortimehandlersSymbolwriteBigUint64ArrayjavascriptperformantformattingInt8ArrayTypedArraytrimRightarthttpmatchAllyamlemitpolyfillECMAScript 2020windowscensorsignaldayjsbatchsymbolES2021exeArrayBufferbootstrap lessstatelessavaextendmkdirserializeUint16ArraymimetypesparentnodecolumnsES3isECMAScript 2023mapvalidationIteratortraverseprototypeinstalluninstallmobiledescriptorfunctionsprotobundlingsetPrototypeOfeslintconfigclientdotenvletjsl10nrgbdeleteeventDispatchersharedenumerablesigintviewjoicheckpropertyreact-hook-formstylesheetcryptoES7bannereslintgradients css3io-tses5assertscoreWeakMapwhatwgtoArrayArray.prototype.includespoint-freepostcssbreaknegativelimitWeakSetdraginferencedom-testing-libraryttysetTypeBoxeventEmittersearchsymlinkspackage manageropenObject.keyslook-upcall-bindgroupBychromexssECMAScript 2022querystringlesscsses2018optimistredactflattenES2017dropeslint-pluginvesttapwhichrequireefficientcurlECMAScript 6varserializerrandomcopywatchFilerangeerrordependency managerparsernamepathObject.isTypeScriptlintlinkcurriedfunctionfast-copyjson-schemastartertakeguidgetterequalityInt16ArraygraphqlinspectargparsesetImmediatelrucolordeep-clonezerodescriptorswgetspinnersvalidatorsidewritableWebSocketstypedcontainsObject.definePropertysequencepnpm9launchairbnbUint8Arraychannelregexcallboundassertextraprefixxdg-opencmdqueryUint32Arraycss lessoperating-systemprocessCSSjsdiffjsonschemaspecdomreducerfantasy-landvariablesruntimeStyleSheetbuffersBigInt64ArrayArray.prototype.filterbddfast-clonetesterfast-deep-copychromium_.extendRxJSArray.prototype.containsconsume
1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago