@kibibit/configit 1.0.0-beta.2 → 1.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <a href="https://github.com/Kibibit/configit" target="blank"><img src="https://github.com/kibibit.png" width="150" ></a>
2
+ <a href="https://github.com/Kibibit/configit" target="blank"><img src="logo.png" width="150" ></a>
3
3
  <h2 align="center">
4
4
  @kibibit/configit
5
5
  </h2>
@@ -8,6 +8,16 @@
8
8
  <a href="https://www.npmjs.com/package/@kibibit/configit"><img src="https://img.shields.io/npm/v/@kibibit/configit/latest.svg?style=for-the-badge&logo=npm&color=CB3837"></a>
9
9
  </p>
10
10
  <p align="center">
11
+ <a href="https://www.npmjs.com/package/@kibibit/configit"><img src="https://img.shields.io/npm/v/@kibibit/configit/beta.svg?logo=npm&color=CB3837"></a>
12
+ <a href="https://codecov.io/gh/Kibibit/configit">
13
+ <img src="https://codecov.io/gh/Kibibit/configit/branch/beta/graph/badge.svg?token=DrXLrpuExK">
14
+ </a>
15
+ <a href="https://github.com/Kibibit/configit/actions/workflows/build.yml">
16
+ <img src="https://github.com/Kibibit/configit/actions/workflows/build.yml/badge.svg?style=flat-square&branch=beta" alt="Build">
17
+ </a>
18
+ <a href="https://github.com/Kibibit/configit/actions/workflows/tests.yml">
19
+ <img src="https://github.com/Kibibit/configit/actions/workflows/tests.yml/badge.svg?branch=beta" alt="Tests">
20
+ </a>
11
21
  <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg"></a>
12
22
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
13
23
  <a href="#contributors-"><img src="https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square" alt="All Contributors"></a>
@@ -15,50 +25,107 @@
15
25
  </p>
16
26
  <p align="center">
17
27
  A general typescript configuration service
28
+
18
29
  </p>
19
30
  <hr>
20
31
 
21
32
  Unless forced to create a new service, this service will return the first created service
22
- ### Usage
33
+
34
+ ## Usage
23
35
 
24
36
  Create a new class to define your configuration.
25
37
  The class should extend the `Config` class from this repo
26
38
  ```typescript
27
- import { Exclude, Expose } from 'class-transformer';
28
- import { IsNumber, Validate, IsString, IsArray } from 'class-validator';
29
- import { Config, JsonSchema } from '@kibibit/configit';
39
+ import { IsNumber, IsString } from 'class-validator';
30
40
 
31
- @Exclude()
32
- export class ProjectConfig extends Config {
33
- @Expose()
41
+ import { BaseConfig, Configuration, ConfigVariable } from '@kibibit/configit';
42
+
43
+ @Configuration()
44
+ export class ProjectConfig extends BaseConfig {
45
+ @ConfigVariable('Server port')
34
46
  @IsNumber()
35
- @Validate(JsonSchema, [
36
- 'Server port'
37
- ])
38
47
  PORT: number;
48
+
49
+ @ConfigVariable([
50
+ 'This is the slack API to talk and report to channel "hello"'
51
+ ])
52
+ @IsString()
53
+ SLACK_API_KEY: string;
54
+ }
55
+
39
56
  }
40
57
  ```
41
58
  Then, in your code, initialize the config service when you bootstrap your application
42
59
  ```typescript
60
+ import express from 'express';
43
61
  import { ConfigService } from '@kibibit/configit';
44
62
  import { ProjectConfig } from './project-config.model';
45
- import express from "express";
46
63
 
47
64
  export const configService = new ConfigService<ProjectConfig>(ProjectConfig);
48
-
49
- console.log(configService.config.PORT);
50
-
51
65
  const app = express();
52
66
 
53
- app.get( "/", ( req, res ) => {
54
- res.send( "Hello world!" );
67
+ app.get( '/', ( req, res ) => {
68
+ res.send( 'Hello world!' );
55
69
  } );
56
70
 
57
71
  app.listen(configService.config.PORT, () => {
58
- console.log( `server started at http://localhost:${ configService.config.PORT }` );
59
- } );
72
+ console.log(
73
+ `server started at http://localhost:${ configService.config.PORT }`
74
+ );
75
+ });
76
+
77
+ ```
78
+
79
+ ### Extending the Configuration Service (Recommended)
80
+ You can extend the configuration to add your own customization and functions!
81
+ ```typescript
82
+ import { chain } from 'lodash';
83
+
84
+ import { ConfigService, IConfigServiceOptions } from '@kibibit/configit';
85
+ import { WinstonLogger } from '@kibibit/nestjs-winston';
86
+
87
+ import { ExtProjectConfig } from './ext-project-config.model';
88
+ import { initializeWinston } from './winston.config';
89
+
90
+ export class ExtConfigService extends ConfigService<ExtProjectConfig> {
91
+ public logger: WinstonLogger;
92
+ constructor(passedConfig?: Partial<ExtProjectConfig>, options: IConfigServiceOptions = {}) {
93
+ super(ExtProjectConfig, passedConfig, options);
94
+
95
+ initializeWinston(this.appRoot);
96
+ this.logger = new WinstonLogger('');
97
+ }
98
+
99
+ getSlackApiObject() {
100
+ const slackApiObject = chain(this.toPlainObject())
101
+ .pickBy((value, key) => key.startsWith('SLACK_'))
102
+ .mapKeys((value, key) => key.replace(/^SLACK_/i, ''))
103
+ .mapKeys((value, key) => key.toLowerCase())
104
+ .value();
105
+
106
+ return slackApiObject;
107
+ }
108
+ }
109
+
110
+ export const configService = new ExtConfigService() as ExtConfigService;
111
+
60
112
  ```
61
113
 
114
+
115
+ ## Features
116
+ - Supports JSON\YAML files\env variables\cli flags as configuration inputs. See `yaml-config` in the examples folder
117
+ - Supports shared configuration files (same file shared for multiple projects)
118
+ - initialize a configuration file with `--saveToFile` or `--init`
119
+ - save configuration files anywhere above your project's package.json
120
+ - forced singleton for a single installation (reuse same class)
121
+ - testable
122
+ - The ability to create json schemas automatically and add descriptions
123
+ to configuration variables
124
+ - Get meaningfull errors when configuration is wrong!
125
+
126
+ ## Examples
127
+ See the examples folder for a variety of usage examples
128
+
62
129
  ## Contributors ✨
63
130
 
64
131
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -78,6 +145,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
78
145
 
79
146
  This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
80
147
 
148
+ <div>Logo made by <a href="https://www.flaticon.com/authors/good-ware" title="Good Ware">Good Ware</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>
149
+ <br>
150
+
81
151
  ## Stay in touch
82
152
 
83
153
  - Author - [Neil Kalman](https://github.com/thatkookooguy)
@@ -1,8 +1,19 @@
1
+ /// <reference types="lodash" />
2
+ import { EFileFormats } from './config.service';
1
3
  export declare const NODE_ENVIRONMENT_OPTIONS: string[];
2
- export declare class Config {
4
+ declare type TClass<T> = (new (partial: Partial<T>) => T);
5
+ export declare class BaseConfig {
6
+ name: string;
3
7
  NODE_ENV: string;
4
8
  saveToFile: boolean;
5
- constructor(partial?: Partial<Config>);
6
- toJsonSchema(): import("openapi3-ts").SchemaObject;
9
+ convert: EFileFormats;
10
+ wrapper: any;
11
+ constructor(partial?: Partial<BaseConfig>);
12
+ toJsonSchema(): import("lodash").Omit<import("openapi3-ts").SchemaObject, "properties.NODE_ENV" | "properties.nodeEnv" | "properties.saveToFile" | "properties.convert" | "properties.wrapper">;
13
+ private cleanFileName;
14
+ setName(genericClass: TClass<BaseConfig>): void;
15
+ getFileName(ext: string, isSharedConfig?: boolean): string;
16
+ getSchemaFileName(): string;
7
17
  }
18
+ export {};
8
19
  //# sourceMappingURL=config.model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.model.d.ts","sourceRoot":"","sources":["../src/config.model.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,wBAAwB,UAMpC,CAAC;AAEF,qBACa,MAAM;IAOjB,QAAQ,SAAiB;IAOzB,UAAU,UAAS;gBAEP,OAAO,GAAE,OAAO,CAAC,MAAM,CAAM;IAIlC,YAAY;CAwBpB"}
1
+ {"version":3,"file":"config.model.d.ts","sourceRoot":"","sources":["../src/config.model.ts"],"names":[],"mappings":";AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,wBAAwB,UAQpC,CAAC;AAEF,aAAK,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAElD,qBACa,UAAU;IACrB,IAAI,EAAE,MAAM,CAAC;IAQb,QAAQ,SAAiB;IAOzB,UAAU,UAAS;IAQnB,OAAO,EAAE,YAAY,CAAC;IAQtB,OAAO,MAAC;gBAEI,OAAO,GAAE,OAAO,CAAC,UAAU,CAAM;IAItC,YAAY;IAsCnB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC;IAIxC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,UAAQ;IAU/C,iBAAiB;CAGlB"}
@@ -9,27 +9,29 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Config = exports.NODE_ENVIRONMENT_OPTIONS = void 0;
13
- const class_transformer_1 = require("class-transformer");
12
+ exports.BaseConfig = exports.NODE_ENVIRONMENT_OPTIONS = void 0;
14
13
  const class_validator_1 = require("class-validator");
15
14
  const class_validator_jsonschema_1 = require("class-validator-jsonschema");
16
15
  const lodash_1 = require("lodash");
16
+ const config_service_1 = require("./config.service");
17
+ const environment_service_1 = require("./environment.service");
17
18
  const json_schema_validator_1 = require("./json-schema.validator");
18
19
  exports.NODE_ENVIRONMENT_OPTIONS = [
19
20
  'google',
20
21
  'development',
21
22
  'production',
22
23
  'test',
23
- 'devcontainer'
24
+ 'devcontainer',
25
+ 'staging',
26
+ 'e2e'
24
27
  ];
25
- let Config = class Config {
28
+ let BaseConfig = class BaseConfig {
26
29
  constructor(partial = {}) {
27
30
  this.NODE_ENV = 'development';
28
31
  this.saveToFile = false;
29
32
  Object.assign(this, partial);
30
33
  }
31
34
  toJsonSchema() {
32
- var _a, _b;
33
35
  const configJsonSchemaObj = (0, class_validator_jsonschema_1.validationMetadatasToSchemas)({
34
36
  additionalConverters: {
35
37
  JsonSchema: (meta) => ({
@@ -39,35 +41,81 @@ let Config = class Config {
39
41
  });
40
42
  const classForSchema = (0, lodash_1.chain)(configJsonSchemaObj)
41
43
  .keys()
42
- .filter((className) => className !== 'Config')
43
- .first()
44
+ .find((className) => className === this.constructor.name)
44
45
  .value();
45
- const configJsonSchema = configJsonSchemaObj[classForSchema];
46
- (_a = configJsonSchema.properties) === null || _a === void 0 ? true : delete _a.nodeEnv;
47
- (_b = configJsonSchema.required) === null || _b === void 0 ? void 0 : _b.splice(configJsonSchema.required.indexOf('nodeEnv'), 1);
46
+ const configJsonSchema = (0, lodash_1.chain)(configJsonSchemaObj[classForSchema])
47
+ .omit([
48
+ 'properties.NODE_ENV',
49
+ 'properties.nodeEnv',
50
+ 'properties.saveToFile',
51
+ 'properties.convert',
52
+ 'properties.wrapper'
53
+ ])
54
+ .value();
55
+ if (configJsonSchema.required) {
56
+ configJsonSchema.required = (0, lodash_1.chain)(configJsonSchema.required)
57
+ .filter((value) => ![
58
+ 'NODE_ENV',
59
+ 'nodeEnv',
60
+ 'saveToFile',
61
+ 'convert',
62
+ 'wrapper'
63
+ ].includes(value))
64
+ .value();
65
+ }
48
66
  return configJsonSchema;
49
67
  }
68
+ cleanFileName(fileName) {
69
+ return (0, lodash_1.chain)(fileName)
70
+ .replace(/Config$/i, '')
71
+ .replace(/Configuration$/i, '')
72
+ .value();
73
+ }
74
+ setName(genericClass) {
75
+ this.name = this.cleanFileName(genericClass.name);
76
+ }
77
+ getFileName(ext, isSharedConfig = false) {
78
+ return [
79
+ '.env.',
80
+ (0, environment_service_1.getEnvironment)(), '.',
81
+ isSharedConfig ? '_shared_.' : '',
82
+ (0, lodash_1.kebabCase)(this.name), '.',
83
+ ext
84
+ ].join('');
85
+ }
86
+ getSchemaFileName() {
87
+ return `${(0, lodash_1.kebabCase)(this.name)}.env.schema.json`;
88
+ }
50
89
  };
51
90
  __decorate([
52
- (0, class_transformer_1.Expose)(),
53
91
  (0, class_validator_1.IsString)(),
54
92
  (0, class_validator_1.IsIn)(exports.NODE_ENVIRONMENT_OPTIONS),
55
- (0, class_validator_1.Validate)(json_schema_validator_1.JsonSchema, [
56
- 'Tells which env file to use and what environment we are running on'
57
- ]),
93
+ (0, json_schema_validator_1.ConfigVariable)('Tells which env file to use and what environment we are running on', { exclude: true }),
58
94
  __metadata("design:type", Object)
59
- ], Config.prototype, "NODE_ENV", void 0);
95
+ ], BaseConfig.prototype, "NODE_ENV", void 0);
60
96
  __decorate([
61
97
  (0, class_validator_1.IsBoolean)(),
62
- (0, class_validator_1.Validate)(json_schema_validator_1.JsonSchema, [
98
+ (0, json_schema_validator_1.ConfigVariable)([
63
99
  'Create a file made out of the internal config. This is mostly for ',
64
100
  'merging command line, environment, and file variables to a single instance'
65
- ]),
101
+ ], { exclude: true }),
102
+ __metadata("design:type", Object)
103
+ ], BaseConfig.prototype, "saveToFile", void 0);
104
+ __decorate([
105
+ (0, class_validator_1.IsEnum)(config_service_1.EFileFormats),
106
+ (0, class_validator_1.IsOptional)(),
107
+ (0, json_schema_validator_1.ConfigVariable)('Save the file to JSON if defaults to YAML and vise versa', { exclude: true }),
108
+ __metadata("design:type", String)
109
+ ], BaseConfig.prototype, "convert", void 0);
110
+ __decorate([
111
+ (0, class_validator_1.IsString)(),
112
+ (0, class_validator_1.IsOptional)(),
113
+ (0, json_schema_validator_1.ConfigVariable)('Object Wrapper for saved file', { exclude: true }),
66
114
  __metadata("design:type", Object)
67
- ], Config.prototype, "saveToFile", void 0);
68
- Config = __decorate([
69
- (0, class_transformer_1.Exclude)(),
115
+ ], BaseConfig.prototype, "wrapper", void 0);
116
+ BaseConfig = __decorate([
117
+ (0, json_schema_validator_1.Configuration)(),
70
118
  __metadata("design:paramtypes", [Object])
71
- ], Config);
72
- exports.Config = Config;
119
+ ], BaseConfig);
120
+ exports.BaseConfig = BaseConfig;
73
121
  //# sourceMappingURL=config.model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.model.js","sourceRoot":"","sources":["../src/config.model.ts"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AAQ,GAAE;IACV,IAAA,sBAAI,EAAC,gCAAwB,CAAC;IAC9B,IAAA,sCAAc,EACb,oEAAoE,EACpE,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB;;4CACwB;AAOzB;IALC,IAAA,2BAAS,GAAE;IACX,IAAA,sCAAc,EAAC;QACd,oEAAoE;QACpE,4EAA4E;KAC7E,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;8CACF;AAQnB;IANC,IAAA,wBAAM,EAAC,6BAAY,CAAC;IACpB,IAAA,4BAAU,GAAE;IACZ,IAAA,sCAAc,EACb,0DAA0D,EAC1D,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB;;2CACqB;AAQtB;IANC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,sCAAc,EACb,+BAA+B,EAC/B,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB;;2CACO;AAhCG,UAAU;IADtB,IAAA,qCAAa,GAAE;;GACH,UAAU,CAoGtB;AApGY,gCAAU"}
@@ -1,25 +1,55 @@
1
- import { Config } from './config.model';
1
+ import { BaseConfig } from './config.model';
2
2
  export interface IConfigServiceOptions {
3
3
  convertToCamelCase?: boolean;
4
+ fileFormat?: EFileFormats;
5
+ sharedConfig?: TClass<BaseConfig>[];
6
+ skipSchema?: boolean;
7
+ schemaFolderName?: string;
8
+ showOverrides?: boolean;
9
+ configFolderRelativePath?: string;
10
+ encryptConfig?: {
11
+ algorithm: string;
12
+ secret: string;
13
+ };
4
14
  }
5
- declare type TClass<T> = new (partial: Partial<T>) => T;
6
- export declare class ConfigService<T extends Config> {
7
- private readonly mode;
15
+ export declare enum EFileFormats {
16
+ json = "json",
17
+ yaml = "yaml",
18
+ jsonc = "jsonc",
19
+ hjson = "hjson"
20
+ }
21
+ export interface IWriteConfigToFileOptions {
22
+ fileFormat: EFileFormats;
23
+ excludeSchema?: boolean;
24
+ objectWrapper?: string;
25
+ outputFolder?: string;
26
+ }
27
+ declare type TClass<T> = (new (partial: Partial<T>) => T);
28
+ export declare class ConfigService<T extends BaseConfig> {
29
+ private fileExtension;
30
+ readonly mode: string;
8
31
  readonly options: IConfigServiceOptions;
9
32
  readonly config?: T;
10
33
  readonly genericClass?: TClass<T>;
11
34
  readonly fileName?: string;
12
- readonly jsonSchemaFullname?: string;
13
- readonly defaultConfigFilePath?: string;
14
35
  readonly configFileName: string;
15
- readonly configFilePath?: string;
36
+ readonly configFileFullPath?: string;
16
37
  readonly configFileRoot?: string;
17
38
  readonly appRoot: string;
18
39
  constructor(givenClass: TClass<T>, passedConfig?: Partial<T>, options?: IConfigServiceOptions);
19
40
  toPlainObject(): Record<string, any>;
41
+ writeConfigToFile({ fileFormat, excludeSchema, objectWrapper, outputFolder }?: IWriteConfigToFileOptions): void;
42
+ private createConfigInstance;
43
+ private initializeNconf;
44
+ private writeSchema;
45
+ private orderObjectKeys;
46
+ private writeSharedSchema;
47
+ private writeSharedConfigToFile;
20
48
  private findRoot;
21
49
  private findConfigRoot;
22
50
  private validateInput;
51
+ private validateSharedInput;
52
+ private generateTerminalTitleBar;
23
53
  }
24
54
  export {};
25
55
  //# sourceMappingURL=config.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../src/config.service.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAOD,aAAK,MAAM,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAQhD,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;IAC5C,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpB,QAAQ,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