UNPKG

2.56 kBTypeScriptView Raw
1export type BindingAddress<T = unknown> = string | BindingKey<T>;
2export declare class BindingKey<ValueType> {
3 readonly key: string;
4 readonly propertyPath?: string | undefined;
5 static readonly PROPERTY_SEPARATOR = "#";
6 /**
7 * Create a new key for a binding bound to a value of type `ValueType`.
8 *
9 * @example
10 *
11 * ```ts
12 * BindingKey.create<string>('application.name');
13 * BindingKey.create<number>('config', 'rest.port);
14 * BindingKey.create<number>('config#rest.port');
15 * ```
16 *
17 * @param key - The binding key. When propertyPath is not provided, the key
18 * is allowed to contain propertyPath as encoded via `BindingKey#toString()`
19 * @param propertyPath - Optional path to a deep property of the bound value.
20 */
21 static create<V>(key: string, propertyPath?: string): BindingKey<V>;
22 private constructor();
23 toString(): string;
24 /**
25 * Get a binding address for retrieving a deep property of the object
26 * bound to the current binding key.
27 *
28 * @param propertyPath - A dot-separated path to a (deep) property, e.g. "server.port".
29 */
30 deepProperty<PropertyValueType>(propertyPath: string): BindingKey<PropertyValueType>;
31 /**
32 * Validate the binding key format. Please note that `#` is reserved.
33 * Returns a string representation of the binding key.
34 *
35 * @param key - Binding key, such as `a`, `a.b`, `a:b`, or `a/b`
36 */
37 static validate<T>(key: BindingAddress<T>): string;
38 /**
39 * Parse a string containing both the binding key and the path to the deeply
40 * nested property to retrieve.
41 *
42 * @param keyWithPath - The key with an optional path,
43 * e.g. "application.instance" or "config#rest.port".
44 */
45 static parseKeyWithPath<T>(keyWithPath: BindingAddress<T>): BindingKey<T>;
46 /**
47 * Name space for configuration binding keys
48 */
49 static CONFIG_NAMESPACE: string;
50 /**
51 * Build a binding key for the configuration of the given binding.
52 * The format is `<key>:$config`
53 *
54 * @param key - Key of the target binding to be configured
55 */
56 static buildKeyForConfig<T>(key?: BindingAddress): BindingAddress<T>;
57 /**
58 * Generate a universally unique binding key.
59 *
60 * Please note the format of they generated key is not specified, you must
61 * not rely on any specific formatting (e.g. UUID style).
62 *
63 * @param namespace - Namespace for the binding
64 */
65 static generate<T>(namespace?: string): BindingKey<T>;
66}