- ConsulConfigSync ⇐
JsonConfig
- JsonConfig
- Parser
The class of Validator
- CustomParseFunction(option) ⇒
ElementParsedResult
- AfterParseFunction(newValue, isFromWatch)
- WatchFunction(error, key, newValue)
- getConfigFromConsulSync(option)
- ConsulOption
- SchemaElement
- Schema :
Object.<string, SchemaElement>
- ElementParsedResult
ConsulConfigSync ⇐ JsonConfig
Kind: global class
Extends: JsonConfig
Param | Type | Default | Description |
---|---|---|---|
option | Object |
||
option.consulAddr | String |
The consul address, in the format of ip:port . |
|
option.pathPrefix | String |
The prefix of consul key element. | |
option.schema | Schema |
The schema object. | |
[option.waitTimeBeforeThrowErrorMs] | Number |
0 |
The wait time before trigger error when the value returned is not expected. The default value is 0 , but it will throw the error in async way even if you set the parameter to 0 . |
[option.timeout4RequestConsulMs] | Number |
5000 |
The timeout milliseconds for consul request. |
[option.retryLimit] | Number |
0 |
The retry times before getting data from consul failed. The default is 0 , which means no limit. |
[option.consulOption] | ConsulOption |
{} |
The consul option used to init a consul client. |
Get All the value.
Kind: instance property of ConsulConfigSync
Overrides: params
Get the value via key name.
Kind: instance method of ConsulConfigSync
Overrides: getValue
Param | Type |
---|---|
key | String |
Kind: global class
Param | Type | Default | Description |
---|---|---|---|
option | Object |
||
option.configObject | Object |
The Json object. | |
option.schema | Schema |
The schema object. | |
[option.waitTimeBeforeThrowErrorMs] | Number |
0 |
The wait time before trigger error when the value returned is not expected. The default value is 0 , but it will throw the error in async way even if you set the parameter to 0 . |
Get All the value.
Kind: instance property of JsonConfig
Get the value via key name.
Kind: instance method of JsonConfig
Param | Type |
---|---|
key | String |
The class of Validator
Kind: global class
Creates an instance of Validator.
Param | Type |
---|---|
option | Object |
option.schema | Schema |
parser.doParseElement(option) ⇒ ElementParsedResult
Parse one config.
Kind: instance method of Parser
Param | Type | Default | Description |
---|---|---|---|
option | Object |
||
option.key | String |
||
option.value | * |
||
[option.isFromWatch] | Boolean |
false |
|
[option.oldValue] | * |
pass to when isFromWatch is true |
Parse all the config.
Kind: instance method of Parser
Param | Type |
---|---|
params | Object |
CustomParseFunction(option) ⇒ ElementParsedResult
Kind: global function
Returns: ElementParsedResult
- the validate result.
Param | Type | Description |
---|---|---|
option | Object |
|
option.key | String |
the key |
option.value | * |
the value you want to validated |
option.schemaElement | SchemaElement |
the element of schema. |
Kind: global function
Param | Type |
---|---|
newValue | * |
isFromWatch | Boolean |
Kind: global function
Param | Type |
---|---|
error | Error | String |
key | String |
newValue | * |
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
option | Object |
||
option.consulAddr | String |
The consul address, in the format of ip:port . |
|
option.pathPrefix | String |
The prefix of consul key element. | |
option.savePath | String |
The full path name of the generated config file. | |
option.keys | Array.<String> |
The consul keys' name. | |
[option.timeoutMs] | Number |
5000 |
The timeout milliseconds for consul request. |
[option.retryLimit] | Number |
0 |
The retry times before getting data from consul failed. The default is 0 , which means no limit. |
[option.consulOption] | ConsulOption |
{} |
The consul option used to init a consul client. |
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
[secure] | Boolean |
false |
enable HTTPS |
[ca] | Array.<String> |
array of strings or Buffers of trusted certificates in PEM format | |
[defaults] | Object |
common method call options that will be included with every call (ex: set default token) |
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
[preferred] | * | function |
when it not empty , it will been used instead of the value get from consul or json object. It can be an function or a value of type of String/Number/Object etc. | |
[required] | Boolean | Array |
false |
indicate whether the current field necessary |
type | Number | JSON | Date | String | Object |
declare the current field's type, it can be Number JSON String Parser.TYPE_FILE Parser.TYPE_DIRECTORY Parser.TYPE_URL or an Object with properties. see |
|
[custom] | CustomParseFunction |
the custom validate function | |
[options] | Object |
the extended options used to check validate. | |
[afterParse] | AfterParseFunction |
the function to do after parse. | |
[watch] | WatchFunction |
the function used in consul watch callback | |
[isWatchDisabled] | Boolean |
false |
whether disable watching the key's changes, default is false. |
Kind: global typedef
Example
{
numberFiled : {
required:true,
type : Number,
options: {
gte: 10,
lte: 1
},
afterParse: function(value) {}
}
}
Example
{
dateField:{
required:[true,'the dateField can not be empty']
type:[Date,'the dataField must be a Date']
}
}
Example
{
objectField: {
type: {
field1: {type: [Number, 'field must be a Number']},
field2: {type: String, required: true}
}
}
}
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
[error] | String | Error |
|
when the value is invalid, the error is not empty. |
value | * |
when the value is valid, return the value , it may be transfromed to the type you want. | |
changed | Boolean |
whether the value is changed, it may be true when the key changed from consul. |