mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Merge pull request #16691 from vesse/convict/validate
[convict] Validate options and chaining
This commit is contained in:
@@ -105,6 +105,18 @@ conf.loadFile(['./configs/always.json', './configs/sometimes.json']);
|
||||
// perform validation
|
||||
|
||||
conf.validate({ strict: true });
|
||||
conf.validate({ allowed: 'strict' });
|
||||
conf.validate({ allowed: 'warn' });
|
||||
|
||||
// Chaining
|
||||
|
||||
conf
|
||||
.loadFile(['./configs/always.json', './configs/sometimes.json'])
|
||||
.loadFile('./config/' + env + '.json')
|
||||
.load({ jsonKey: 'jsonValue' })
|
||||
.set('key', 'value')
|
||||
.validate({ allowed: 'warn' })
|
||||
.toString();
|
||||
|
||||
var port: number = conf.default('port');
|
||||
|
||||
|
||||
Vendored
+60
-7
@@ -1,11 +1,26 @@
|
||||
// Type definitions for node-convict v0.6.0
|
||||
// Type definitions for node-convict v3.0.0
|
||||
// Project: https://github.com/mozilla/node-convict
|
||||
// Definitions by: Wim Looman <https://github.com/Nemo157>
|
||||
// Definitions by: Wim Looman <https://github.com/Nemo157>, Vesa Poikajärvi <https://github.com/vesse>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
declare namespace convict {
|
||||
|
||||
type ValidationMethod = 'strict' | 'warn';
|
||||
|
||||
interface ValidateOptions {
|
||||
/**
|
||||
* If set to warn, any properties specified in config files that are not declared in
|
||||
* the schema will print a warning. This is the default behavior. If set to strict,
|
||||
* any properties specified in config files that are not declared in the schema will
|
||||
* throw errors. This is to ensure that the schema and the config files are in sync.
|
||||
*/
|
||||
allowed?: ValidationMethod;
|
||||
|
||||
/** @deprecated use allowed instead */
|
||||
strict?: boolean;
|
||||
}
|
||||
|
||||
interface Format {
|
||||
name?: string;
|
||||
validate?: (val: any) => void;
|
||||
@@ -34,14 +49,52 @@ declare namespace convict {
|
||||
}
|
||||
|
||||
interface Config {
|
||||
/**
|
||||
* @returns the current value of the name property. name can use dot
|
||||
* notation to reference nested values
|
||||
*/
|
||||
get(name: string): any;
|
||||
/**
|
||||
* @returns the default value of the name property. name can use dot
|
||||
* notation to reference nested values
|
||||
*/
|
||||
default(name: string): any;
|
||||
/**
|
||||
* @returns true if the property name is defined, or false otherwise
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
set(name: string, value: any): void;
|
||||
load(conf: Object): void;
|
||||
loadFile(file: string): void;
|
||||
loadFile(files: string[]): void;
|
||||
validate(options?: { strict?: boolean }): void;
|
||||
/**
|
||||
* Sets the value of name to value. name can use dot notation to reference
|
||||
* nested values, e.g. "database.port". If objects in the chain don't yet
|
||||
* exist, they will be initialized to empty objects
|
||||
*
|
||||
* @return {Config} instance
|
||||
*/
|
||||
set(name: string, value: any): Config;
|
||||
/**
|
||||
* Loads and merges a JavaScript object into config
|
||||
*
|
||||
* @return {Config} instance
|
||||
*/
|
||||
load(conf: Object): Config;
|
||||
/**
|
||||
* Loads and merges one JSON configuration file into config
|
||||
*
|
||||
* @return {Config} instance
|
||||
*/
|
||||
loadFile(file: string): Config;
|
||||
/**
|
||||
* Loads and merges multiple JSON configuration files into config
|
||||
*
|
||||
* @return {Config} instance
|
||||
*/
|
||||
loadFile(files: string[]): Config;
|
||||
/**
|
||||
* Validates config against the schema used to initialize it
|
||||
*
|
||||
* @param options
|
||||
*/
|
||||
validate(options?: ValidateOptions): Config;
|
||||
/**
|
||||
* Exports all the properties (that is the keys and their current values) as a {JSON} {Object}
|
||||
* @returns {Object} A {JSON} compliant {Object}
|
||||
|
||||
Reference in New Issue
Block a user