UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
3// Node module: @loopback/context
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.configBindingKeyFor = exports.DefaultConfigurationResolver = void 0;
8const binding_key_1 = require("./binding-key");
9/**
10 * Resolver for configurations of bindings
11 */
12class DefaultConfigurationResolver {
13 constructor(context) {
14 this.context = context;
15 }
16 getConfigAsValueOrPromise(key, propertyPath, resolutionOptions) {
17 propertyPath = propertyPath !== null && propertyPath !== void 0 ? propertyPath : '';
18 const configKey = configBindingKeyFor(key, propertyPath);
19 const options = Object.assign({ optional: true }, resolutionOptions);
20 return this.context.getValueOrPromise(configKey, options);
21 }
22}
23exports.DefaultConfigurationResolver = DefaultConfigurationResolver;
24/**
25 * Create binding key for configuration of the binding
26 * @param key - Binding key for the target binding
27 * @param propertyPath - Property path for the configuration
28 */
29function configBindingKeyFor(key, propertyPath) {
30 return binding_key_1.BindingKey.create(binding_key_1.BindingKey.buildKeyForConfig(key).toString(), propertyPath);
31}
32exports.configBindingKeyFor = configBindingKeyFor;
33//# sourceMappingURL=binding-config.js.map
\No newline at end of file