* Get the value bound to the given key. * * This is an internal version that preserves the dual sync/async result * of `Binding#getValue()`. Users should use `get()` or `getSync()` instead. * * @example * * ```ts * // get the value bound to "application.instance" * ctx.get
(
keyWithPath: BindingAddress<ValueType>,
optionsOrSession?: ResolutionOptionsOrSession,
)
| 891 | * @internal |
| 892 | */ |
| 893 | getValueOrPromise<ValueType>( |
| 894 | keyWithPath: BindingAddress<ValueType>, |
| 895 | optionsOrSession?: ResolutionOptionsOrSession, |
| 896 | ): ValueOrPromise<ValueType | undefined> { |
| 897 | const {key, propertyPath} = BindingKey.parseKeyWithPath(keyWithPath); |
| 898 | |
| 899 | const options = asResolutionOptions(optionsOrSession); |
| 900 | |
| 901 | const binding = this.getBinding<ValueType>(key, {optional: true}); |
| 902 | if (binding == null) { |
| 903 | if (options.optional) return undefined; |
| 904 | throw new ResolutionError( |
| 905 | `The key '${key}' is not bound to any value in context ${this.name}`, |
| 906 | { |
| 907 | context: this, |
| 908 | binding: Binding.bind(key), |
| 909 | options, |
| 910 | }, |
| 911 | ); |
| 912 | } |
| 913 | |
| 914 | const boundValue = binding.getValue(this, options); |
| 915 | return propertyPath == null || propertyPath === '' |
| 916 | ? boundValue |
| 917 | : transformValueOrPromise(boundValue, v => |
| 918 | getDeepProperty<ValueType>(v, propertyPath), |
| 919 | ); |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Create a plain JSON object for the context |
no test coverage detected