@kibibit/configit 1.0.0-beta.1 → 1.0.0-beta.16
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 +88 -19
- package/lib/config.model.d.ts +14 -3
- package/lib/config.model.d.ts.map +1 -1
- package/lib/config.model.js +67 -21
- package/lib/config.model.js.map +1 -1
- package/lib/config.service.d.ts +36 -7
- package/lib/config.service.d.ts.map +1 -1
- package/lib/config.service.js +265 -41
- package/lib/config.service.js.map +1 -1
- package/lib/environment.service.d.ts +3 -0
- package/lib/environment.service.d.ts.map +1 -0
- package/lib/environment.service.js +15 -0
- package/lib/environment.service.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/json-schema.validator.d.ts +4 -4
- package/lib/json-schema.validator.d.ts.map +1 -1
- package/lib/json-schema.validator.js +19 -2
- package/lib/json-schema.validator.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -6
- package/src/__snapshots__/config.errors.spec.ts.snap +12 -0
- package/src/__snapshots__/config.model.spec.ts.snap +22 -0
- package/src/__snapshots__/config.service.spec.ts.snap +241 -0
- package/src/config.errors.spec.ts +26 -0
- package/src/config.model.spec.ts +52 -0
- package/src/config.model.ts +82 -22
- package/src/config.service.spec.ts +307 -0
- package/src/config.service.ts +377 -55
- package/src/environment.service.ts +13 -0
- package/src/index.ts +1 -0
- package/src/json-schema.validator.ts +29 -1
- package/src/pizza.config.model.mock.ts +33 -0
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="
|
|
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,51 +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
33
|
|
|
23
|
-
|
|
34
|
+
## Usage
|
|
24
35
|
|
|
25
36
|
Create a new class to define your configuration.
|
|
26
37
|
The class should extend the `Config` class from this repo
|
|
27
38
|
```typescript
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
import {
|
|
39
|
+
import { IsNumber, IsString } from 'class-validator';
|
|
40
|
+
|
|
41
|
+
import { BaseConfig, Configuration, ConfigVariable } from '@kibibit/configit';
|
|
31
42
|
|
|
32
|
-
@
|
|
33
|
-
export class ProjectConfig extends
|
|
34
|
-
@
|
|
43
|
+
@Configuration()
|
|
44
|
+
export class ProjectConfig extends BaseConfig {
|
|
45
|
+
@ConfigVariable('Server port')
|
|
35
46
|
@IsNumber()
|
|
36
|
-
@Validate(JsonSchema, [
|
|
37
|
-
'Server port'
|
|
38
|
-
])
|
|
39
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
|
+
|
|
40
56
|
}
|
|
41
57
|
```
|
|
42
58
|
Then, in your code, initialize the config service when you bootstrap your application
|
|
43
59
|
```typescript
|
|
60
|
+
import express from 'express';
|
|
44
61
|
import { ConfigService } from '@kibibit/configit';
|
|
45
62
|
import { ProjectConfig } from './project-config.model';
|
|
46
|
-
import express from "express";
|
|
47
63
|
|
|
48
64
|
export const configService = new ConfigService<ProjectConfig>(ProjectConfig);
|
|
49
|
-
|
|
50
|
-
console.log(configService.config.PORT);
|
|
51
|
-
|
|
52
65
|
const app = express();
|
|
53
66
|
|
|
54
|
-
app.get(
|
|
55
|
-
res.send(
|
|
67
|
+
app.get( '/', ( req, res ) => {
|
|
68
|
+
res.send( 'Hello world!' );
|
|
56
69
|
} );
|
|
57
70
|
|
|
58
71
|
app.listen(configService.config.PORT, () => {
|
|
59
|
-
console.log(
|
|
60
|
-
}
|
|
72
|
+
console.log(
|
|
73
|
+
`server started at http://localhost:${ configService.config.PORT }`
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
61
77
|
```
|
|
62
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
|
+
|
|
112
|
+
```
|
|
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
|
+
|
|
63
129
|
## Contributors ✨
|
|
64
130
|
|
|
65
131
|
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
@@ -79,6 +145,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
79
145
|
|
|
80
146
|
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
|
|
81
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
|
+
|
|
82
151
|
## Stay in touch
|
|
83
152
|
|
|
84
153
|
- Author - [Neil Kalman](https://github.com/thatkookooguy)
|
package/lib/config.model.d.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
import { EFileFormats } from './config.service';
|
|
1
3
|
export declare const NODE_ENVIRONMENT_OPTIONS: string[];
|
|
2
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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":"
|
|
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,UAMpC,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"}
|
package/lib/config.model.js
CHANGED
|
@@ -9,11 +9,12 @@ 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.
|
|
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',
|
|
@@ -22,14 +23,13 @@ exports.NODE_ENVIRONMENT_OPTIONS = [
|
|
|
22
23
|
'test',
|
|
23
24
|
'devcontainer'
|
|
24
25
|
];
|
|
25
|
-
let
|
|
26
|
+
let BaseConfig = class BaseConfig {
|
|
26
27
|
constructor(partial = {}) {
|
|
27
28
|
this.NODE_ENV = 'development';
|
|
28
29
|
this.saveToFile = false;
|
|
29
30
|
Object.assign(this, partial);
|
|
30
31
|
}
|
|
31
32
|
toJsonSchema() {
|
|
32
|
-
var _a, _b;
|
|
33
33
|
const configJsonSchemaObj = (0, class_validator_jsonschema_1.validationMetadatasToSchemas)({
|
|
34
34
|
additionalConverters: {
|
|
35
35
|
JsonSchema: (meta) => ({
|
|
@@ -39,35 +39,81 @@ let Config = class Config {
|
|
|
39
39
|
});
|
|
40
40
|
const classForSchema = (0, lodash_1.chain)(configJsonSchemaObj)
|
|
41
41
|
.keys()
|
|
42
|
-
.
|
|
43
|
-
.first()
|
|
42
|
+
.find((className) => className === this.constructor.name)
|
|
44
43
|
.value();
|
|
45
|
-
const configJsonSchema = configJsonSchemaObj[classForSchema]
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const configJsonSchema = (0, lodash_1.chain)(configJsonSchemaObj[classForSchema])
|
|
45
|
+
.omit([
|
|
46
|
+
'properties.NODE_ENV',
|
|
47
|
+
'properties.nodeEnv',
|
|
48
|
+
'properties.saveToFile',
|
|
49
|
+
'properties.convert',
|
|
50
|
+
'properties.wrapper'
|
|
51
|
+
])
|
|
52
|
+
.value();
|
|
53
|
+
if (configJsonSchema.required) {
|
|
54
|
+
configJsonSchema.required = (0, lodash_1.chain)(configJsonSchema.required)
|
|
55
|
+
.filter((value) => ![
|
|
56
|
+
'NODE_ENV',
|
|
57
|
+
'nodeEnv',
|
|
58
|
+
'saveToFile',
|
|
59
|
+
'convert',
|
|
60
|
+
'wrapper'
|
|
61
|
+
].includes(value))
|
|
62
|
+
.value();
|
|
63
|
+
}
|
|
48
64
|
return configJsonSchema;
|
|
49
65
|
}
|
|
66
|
+
cleanFileName(fileName) {
|
|
67
|
+
return (0, lodash_1.chain)(fileName)
|
|
68
|
+
.replace(/Config$/i, '')
|
|
69
|
+
.replace(/Configuration$/i, '')
|
|
70
|
+
.value();
|
|
71
|
+
}
|
|
72
|
+
setName(genericClass) {
|
|
73
|
+
this.name = this.cleanFileName(genericClass.name);
|
|
74
|
+
}
|
|
75
|
+
getFileName(ext, isSharedConfig = false) {
|
|
76
|
+
return [
|
|
77
|
+
'.env.',
|
|
78
|
+
(0, environment_service_1.getEnvironment)(), '.',
|
|
79
|
+
isSharedConfig ? '_shared_.' : '',
|
|
80
|
+
(0, lodash_1.kebabCase)(this.name), '.',
|
|
81
|
+
ext
|
|
82
|
+
].join('');
|
|
83
|
+
}
|
|
84
|
+
getSchemaFileName() {
|
|
85
|
+
return `${(0, lodash_1.kebabCase)(this.name)}.env.schema.json`;
|
|
86
|
+
}
|
|
50
87
|
};
|
|
51
88
|
__decorate([
|
|
52
|
-
(0, class_transformer_1.Expose)(),
|
|
53
89
|
(0, class_validator_1.IsString)(),
|
|
54
90
|
(0, class_validator_1.IsIn)(exports.NODE_ENVIRONMENT_OPTIONS),
|
|
55
|
-
(0,
|
|
56
|
-
'Tells which env file to use and what environment we are running on'
|
|
57
|
-
]),
|
|
91
|
+
(0, json_schema_validator_1.ConfigVariable)('Tells which env file to use and what environment we are running on', { exclude: true }),
|
|
58
92
|
__metadata("design:type", Object)
|
|
59
|
-
],
|
|
93
|
+
], BaseConfig.prototype, "NODE_ENV", void 0);
|
|
60
94
|
__decorate([
|
|
61
95
|
(0, class_validator_1.IsBoolean)(),
|
|
62
|
-
(0,
|
|
96
|
+
(0, json_schema_validator_1.ConfigVariable)([
|
|
63
97
|
'Create a file made out of the internal config. This is mostly for ',
|
|
64
98
|
'merging command line, environment, and file variables to a single instance'
|
|
65
|
-
]),
|
|
99
|
+
], { exclude: true }),
|
|
100
|
+
__metadata("design:type", Object)
|
|
101
|
+
], BaseConfig.prototype, "saveToFile", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, class_validator_1.IsEnum)(config_service_1.EFileFormats),
|
|
104
|
+
(0, class_validator_1.IsOptional)(),
|
|
105
|
+
(0, json_schema_validator_1.ConfigVariable)('Save the file to JSON if defaults to YAML and vise versa', { exclude: true }),
|
|
106
|
+
__metadata("design:type", String)
|
|
107
|
+
], BaseConfig.prototype, "convert", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
(0, class_validator_1.IsString)(),
|
|
110
|
+
(0, class_validator_1.IsOptional)(),
|
|
111
|
+
(0, json_schema_validator_1.ConfigVariable)('Object Wrapper for saved file', { exclude: true }),
|
|
66
112
|
__metadata("design:type", Object)
|
|
67
|
-
],
|
|
68
|
-
|
|
69
|
-
(0,
|
|
113
|
+
], BaseConfig.prototype, "wrapper", void 0);
|
|
114
|
+
BaseConfig = __decorate([
|
|
115
|
+
(0, json_schema_validator_1.Configuration)(),
|
|
70
116
|
__metadata("design:paramtypes", [Object])
|
|
71
|
-
],
|
|
72
|
-
exports.
|
|
117
|
+
], BaseConfig);
|
|
118
|
+
exports.BaseConfig = BaseConfig;
|
|
73
119
|
//# sourceMappingURL=config.model.js.map
|
package/lib/config.model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.model.js","sourceRoot":"","sources":["../src/config.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"config.model.js","sourceRoot":"","sources":["../src/config.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAM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ACb,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"}
|
package/lib/config.service.d.ts
CHANGED
|
@@ -1,25 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseConfig } from './config.model';
|
|
2
2
|
export interface IConfigServiceOptions {
|
|
3
3
|
convertToCamelCase?: boolean;
|
|
4
|
+
fileFormat?: EFileFormats;
|
|
5
|
+
sharedConfig?: TClass<BaseConfig>[];
|
|
6
|
+
schemaFolderName?: string;
|
|
7
|
+
showOverrides?: boolean;
|
|
8
|
+
configFolderRelativePath?: string;
|
|
9
|
+
encryptConfig?: {
|
|
10
|
+
algorithm: string;
|
|
11
|
+
secret: string;
|
|
12
|
+
};
|
|
4
13
|
}
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
export declare enum EFileFormats {
|
|
15
|
+
json = "json",
|
|
16
|
+
yaml = "yaml",
|
|
17
|
+
jsonc = "jsonc",
|
|
18
|
+
hjson = "hjson"
|
|
19
|
+
}
|
|
20
|
+
export interface IWriteConfigToFileOptions {
|
|
21
|
+
fileFormat: EFileFormats;
|
|
22
|
+
excludeSchema?: boolean;
|
|
23
|
+
objectWrapper?: string;
|
|
24
|
+
outputFolder?: string;
|
|
25
|
+
}
|
|
26
|
+
declare type TClass<T> = (new (partial: Partial<T>) => T);
|
|
27
|
+
export declare class ConfigService<T extends BaseConfig> {
|
|
28
|
+
private fileExtension;
|
|
29
|
+
readonly mode: string;
|
|
8
30
|
readonly options: IConfigServiceOptions;
|
|
9
31
|
readonly config?: T;
|
|
10
32
|
readonly genericClass?: TClass<T>;
|
|
11
33
|
readonly fileName?: string;
|
|
12
|
-
readonly jsonSchemaFullname?: string;
|
|
13
|
-
readonly defaultConfigFilePath?: string;
|
|
14
34
|
readonly configFileName: string;
|
|
15
|
-
readonly
|
|
35
|
+
readonly configFileFullPath?: string;
|
|
16
36
|
readonly configFileRoot?: string;
|
|
17
37
|
readonly appRoot: string;
|
|
18
38
|
constructor(givenClass: TClass<T>, passedConfig?: Partial<T>, options?: IConfigServiceOptions);
|
|
19
39
|
toPlainObject(): Record<string, any>;
|
|
40
|
+
writeConfigToFile({ fileFormat, excludeSchema, objectWrapper, outputFolder }?: IWriteConfigToFileOptions): void;
|
|
41
|
+
private createConfigInstance;
|
|
42
|
+
private initializeNconf;
|
|
43
|
+
private writeSchema;
|
|
44
|
+
private orderObjectKeys;
|
|
45
|
+
private writeSharedSchema;
|
|
46
|
+
private writeSharedConfigToFile;
|
|
20
47
|
private findRoot;
|
|
21
48
|
private findConfigRoot;
|
|
22
49
|
private validateInput;
|
|
50
|
+
private validateSharedInput;
|
|
51
|
+
private generateTerminalTitleBar;
|
|
23
52
|
}
|
|
24
53
|
export {};
|
|
25
54
|
//# sourceMappingURL=config.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../src/config.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.service.d.ts","sourceRoot":"","sources":["../src/config.service.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAY5C,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,wBAAwB,CAAC,EAAE,MAAM,CAAC;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