@rosen-bridge/config 0.1.0 → 0.2.1
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/CHANGELOG.md +12 -0
- package/dist/config.d.ts +143 -126
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +570 -556
- package/dist/index.js +1 -1
- package/dist/schema/Validators/fieldProperties.d.ts +27 -24
- package/dist/schema/Validators/fieldProperties.d.ts.map +1 -1
- package/dist/schema/Validators/fieldProperties.js +215 -248
- package/dist/schema/types/fields.d.ts +24 -22
- package/dist/schema/types/fields.d.ts.map +1 -1
- package/dist/schema/types/fields.js +1 -1
- package/dist/schema/types/validations.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/value/validators.d.ts.map +1 -1
- package/dist/value/validators.js +149 -176
- package/lib/config.ts +128 -50
- package/lib/schema/Validators/fieldProperties.ts +18 -0
- package/lib/schema/types/fields.ts +8 -1
- package/lib/value/validators.ts +5 -0
- package/package.json +1 -1
- package/tests/config.spec.ts +61 -1
- package/tests/configTestData.ts +251 -12
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -2,130 +2,147 @@ import { IConfig } from 'config';
|
|
|
2
2
|
import { ConfigField, ConfigSchema } from './schema/types/fields';
|
|
3
3
|
import { When } from './schema/types/validations';
|
|
4
4
|
export declare class ConfigValidator {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
5
|
+
private schema;
|
|
6
|
+
constructor(schema: ConfigSchema);
|
|
7
|
+
/**
|
|
8
|
+
* validates the passed config against the instance's schema
|
|
9
|
+
*
|
|
10
|
+
* @param {Record<string, any>} config
|
|
11
|
+
*/
|
|
12
|
+
validateConfig(config: Record<string, any>): void;
|
|
13
|
+
/**
|
|
14
|
+
* traverses and validates a subconfig using the subschema
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
* @param {Record<string, any>} config
|
|
18
|
+
* @param {Record<string, any>} subConfig
|
|
19
|
+
* @param {ConfigSchema} subSchema
|
|
20
|
+
* @param {string[]} path
|
|
21
|
+
* @memberof ConfigValidator
|
|
22
|
+
*/
|
|
23
|
+
private validateSubConfig;
|
|
24
|
+
/**
|
|
25
|
+
* sets an object's specific subtree to the specified value
|
|
26
|
+
*
|
|
27
|
+
* @static
|
|
28
|
+
* @param {Record<string, any>} obj
|
|
29
|
+
* @param {*} newValue
|
|
30
|
+
* @param {string[]} path
|
|
31
|
+
* @return {*}
|
|
32
|
+
* @memberof ConfigValidator
|
|
33
|
+
*/
|
|
34
|
+
static modifyObject(obj: Record<string, any>, newValue: any, path: string[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* validates a value in config object
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @param {*} value
|
|
40
|
+
* @param {ConfigField} field the field specification in schema
|
|
41
|
+
* @param {Record<string, any>} config the config object
|
|
42
|
+
*/
|
|
43
|
+
private validateValue;
|
|
44
|
+
/**
|
|
45
|
+
* determines if a when clause in validations section of a schema field is
|
|
46
|
+
* satisfied
|
|
47
|
+
*
|
|
48
|
+
* @param {When} when
|
|
49
|
+
* @param {Record<string, any>} config
|
|
50
|
+
* @return {boolean}
|
|
51
|
+
*/
|
|
52
|
+
isWhenTrue: (when: When, config: Record<string, any>) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* returns the value at specified path in config object
|
|
55
|
+
*
|
|
56
|
+
* @static
|
|
57
|
+
* @param {Record<string, any>} config
|
|
58
|
+
* @param {string[]} path
|
|
59
|
+
* @return {*}
|
|
60
|
+
*/
|
|
61
|
+
static valueAt: (config: Record<string, any>, path: string[]) => any;
|
|
62
|
+
/**
|
|
63
|
+
* validates this.schema and throws exception if any errors found
|
|
64
|
+
*/
|
|
65
|
+
private validateSchema;
|
|
66
|
+
/**
|
|
67
|
+
* validates config key name
|
|
68
|
+
*
|
|
69
|
+
* @param {string} name
|
|
70
|
+
*/
|
|
71
|
+
private validateConfigName;
|
|
72
|
+
/**
|
|
73
|
+
* validates passed schema field structure
|
|
74
|
+
*
|
|
75
|
+
* @param {ConfigField} field
|
|
76
|
+
*/
|
|
77
|
+
private validateSchemaField;
|
|
78
|
+
/**
|
|
79
|
+
* returns a field corresponding to a path in schema tree
|
|
80
|
+
*
|
|
81
|
+
* @param {string[]} path
|
|
82
|
+
* @return {(ConfigField | undefined)} returns undefined if field is not found
|
|
83
|
+
*/
|
|
84
|
+
getSchemaField: (path: string[]) => ConfigField | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* extracts default values from a schema
|
|
87
|
+
*
|
|
88
|
+
* @return {Record<string, any>} object of default values
|
|
89
|
+
*/
|
|
90
|
+
generateDefault: () => Record<string, any>;
|
|
91
|
+
/**
|
|
92
|
+
* generates compatible TypeScript interface for this instance's schema
|
|
93
|
+
*
|
|
94
|
+
* @param {string} name the name of root type
|
|
95
|
+
* @return {string}
|
|
96
|
+
*/
|
|
97
|
+
generateTSTypes: (name: string) => string;
|
|
98
|
+
/**
|
|
99
|
+
* generates a TypeScript interface definition for passed name and attributes
|
|
100
|
+
*
|
|
101
|
+
* @param {string} name
|
|
102
|
+
* @param {Array<[string, string]>} attributes
|
|
103
|
+
* @return {string}
|
|
104
|
+
*/
|
|
105
|
+
private genTSInterface;
|
|
106
|
+
/**
|
|
107
|
+
* returns a characteristic object for values at a specific node config level
|
|
108
|
+
*
|
|
109
|
+
* @param {IConfig} config
|
|
110
|
+
* @param {string} level
|
|
111
|
+
* @return {Record<string, any>}
|
|
112
|
+
*/
|
|
113
|
+
getConfigForLevel(config: IConfig, level: string): Record<string, any>;
|
|
114
|
+
/**
|
|
115
|
+
*traverses the config schema depth first to produce characteristic object
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
118
|
+
* @static
|
|
119
|
+
* @param {ConfigSchema} schema
|
|
120
|
+
* @param {string[]} path
|
|
121
|
+
* @param {IConfigSource[]} higherLevelSources
|
|
122
|
+
* @param {(IConfigSource | undefined)} currentLevelSource
|
|
123
|
+
* @param {IConfigSource[]} lowerLevelSources
|
|
124
|
+
* @return {Record<string, any>}
|
|
125
|
+
* @memberof ConfigValidator
|
|
126
|
+
*/
|
|
127
|
+
private static processConfigForLevelNode;
|
|
128
|
+
/**
|
|
129
|
+
* returns a list of config sources used by node config package, ordered from
|
|
130
|
+
* the lowest to the highest priority
|
|
131
|
+
*
|
|
132
|
+
* @static
|
|
133
|
+
* @param {IConfig} config
|
|
134
|
+
* @return {string[]}
|
|
135
|
+
*/
|
|
136
|
+
private static getNodeConfigLevels;
|
|
137
|
+
/**
|
|
138
|
+
* validates a config object and writes it to the node-config file
|
|
139
|
+
* corresponding to the passed level
|
|
140
|
+
*
|
|
141
|
+
* @param {Record<string, any>} configObj
|
|
142
|
+
* @param {IConfig} config
|
|
143
|
+
* @param {string} level output node-config file level
|
|
144
|
+
* @param {string} format the format of the output file
|
|
145
|
+
*/
|
|
146
|
+
validateAndWriteConfig: (configObj: Record<string, any>, config: IConfig, level: string, format: string) => void;
|
|
130
147
|
}
|
|
131
|
-
//# sourceMappingURL=config.d.ts.map
|
|
148
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,QAAQ,CAAC;AAShD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B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