UNPKG

1.93 kBTypeScriptView Raw
1import { BindingAddress, BindingKey } from './binding-key';
2import { Context } from './context';
3import { ResolutionOptions } from './resolution-session';
4import { ValueOrPromise } from './value-promise';
5/**
6 * Resolver for configuration of bindings. It's responsible for finding
7 * corresponding configuration for a given binding key.
8 *
9 * By default, `undefined` is expected if no configuration is provided. The
10 * behavior can be overridden by setting `optional` to `false` in resolution
11 * options.
12 */
13export interface ConfigurationResolver {
14 /**
15 * Resolve config for the binding key
16 *
17 * @param key - Binding key
18 * @param propertyPath - Property path for the option. For example, `x.y`
19 * requests for `<config>.x.y`. If not set, the `config` object will be
20 * returned.
21 * @param resolutionOptions - Options for the resolution.
22 * - optional: if not set or set to `true`, `undefined` will be returned if
23 * no corresponding value is found. Otherwise, an error will be thrown.
24 */
25 getConfigAsValueOrPromise<ConfigValueType>(key: BindingAddress<unknown>, propertyPath?: string, resolutionOptions?: ResolutionOptions): ValueOrPromise<ConfigValueType | undefined>;
26}
27/**
28 * Resolver for configurations of bindings
29 */
30export declare class DefaultConfigurationResolver implements ConfigurationResolver {
31 readonly context: Context;
32 constructor(context: Context);
33 getConfigAsValueOrPromise<ConfigValueType>(key: BindingAddress<unknown>, propertyPath?: string, resolutionOptions?: ResolutionOptions): ValueOrPromise<ConfigValueType | undefined>;
34}
35/**
36 * Create binding key for configuration of the binding
37 * @param key - Binding key for the target binding
38 * @param propertyPath - Property path for the configuration
39 */
40export declare function configBindingKeyFor<ConfigValueType = unknown>(key: BindingAddress, propertyPath?: string): BindingKey<ConfigValueType>;