Merge pull request #7699 from jppellerin/confidence-add

Definition files for hapijs/confidence
This commit is contained in:
Horiuchi_H
2016-01-20 17:39:54 +09:00
2 changed files with 127 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
/// <reference path="confidence.d.ts" />
import Confidence = require('confidence');
let criteria = {
"env": "production",
"platform": "ios",
"xfactor": "yes",
"random": {
"a": 15
}
};
/**
* The configurations in Confidence style
*/
let config = {
"key1": "abc",
"key2": {
"$filter": "env",
"production": {
"deeper": {
"$value": "value"
}
},
"$default": {
"$filter": "platform",
"android": 0,
"ios": 1,
"$default": 2
}
},
"key3": {
"sub1": 123,
"sub2": {
"$filter": "xfactor",
"yes": 6
}
},
"ab": {
"$filter": "random.a",
"$range": [
{ "limit": 10, "value": 4 },
{ "limit": 20, "value": 5 }
],
"$default": 6
},
"$meta": {
"description": "example file"
}
};
/**
* Creates an empty configuration storage container
*/
let store = new Confidence.Store(config);
/**
* Validates the provided configuration, clears any existing configuration, then loads the configuration
*/
store.load(config);
/**
* Retrieves a value from the configuration document after applying the provided criteria
*/
store.get('/key1');
//criteria - optional object
store.get('/key2', criteria);
/**
* Retrieves the metadata (if any) from the configuration document after applying the provided criteria
*/
store.meta('/key1');
//criteria - optional object
store.meta('/key2', criteria);
+48
View File
@@ -0,0 +1,48 @@
// Type definitions for Confidence v1.4.2
// Project: https://github.com/hapijs/confidence.git
// Definitions by: Jean-Philippe Pellerin <https://github.com/jppellerin>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* Confidence is a configuration document format, an API, and a foundation for A/B testing.
* The configuration format is designed to work with any existing JSON-based configuration,
* serving values based on object path ('/a/b/c' translates to a.b.c). In addition,
* confidence defines special $-prefixed keys used to filter values for a given criteria.
*/
declare module 'confidence' {
export class Store {
/**
* @constructor
* @param {any} document - the configuration document for this document store
*/
constructor(document?: any);
/**
* Validates the provided configuration, clears any existing configuration, then loads the configuration where:
* @param {any} document - an object containing a confidence configuration object generated from a parsed JSON document. If the document is invlaid, will throw an error.
*/
load(document: any): void;
/**
* Retrieves a value from the configuration document after applying the provided criteria where:
* @param {string} key - the requested key path. All keys must begin with '/'. '/' returns the the entire document.
* @param {any} criteria - optional object used as criteria for applying filters in the configuration document. Defaults to {}.
*
* @return {any} Returns the value found after applying the criteria. If the key is invalid or not found, returns undefined.
*/
get(key: string, criteria?: any): any;
/**
* Retrieves the metadata (if any) from the configuration document after applying the provided criteria where:
* @param {string} key - the requested key path. All keys must begin with '/'. '/' returns the the entire document.
* @param {any} criteria - optional object used as criteria for applying filters in the configuration document. Defaults to {}.
*
* @return {any} Returns the metadata found after applying the criteria. If the key is invalid or not found, or if no metadata is available, returns undefined.
*/
meta(key: string, criteria?: any): any;
}
}