* Resolve values for the matching bindings * @param session - Resolution session
(session?: ResolutionOptionsOrSession)
| 194 | * @param session - Resolution session |
| 195 | */ |
| 196 | resolve(session?: ResolutionOptionsOrSession): ValueOrPromise<T[]> { |
| 197 | debug('Resolving values'); |
| 198 | if (this._cachedValues != null) { |
| 199 | return this.getCachedValues(); |
| 200 | } |
| 201 | const bindings = this.bindings; |
| 202 | let result = resolveList(bindings, b => { |
| 203 | const options = { |
| 204 | ...this.resolutionOptions, |
| 205 | ...asResolutionOptions(session), |
| 206 | }; |
| 207 | // https://github.com/loopbackio/loopback-next/issues/9041 |
| 208 | // We should start with a new session for `view` resolution to avoid |
| 209 | // possible circular dependencies |
| 210 | options.session = undefined; |
| 211 | return b.getValue(this.context, options); |
| 212 | }); |
| 213 | if (isPromiseLike(result)) { |
| 214 | result = result.then(values => { |
| 215 | const list = values.filter(v => v != null) as T[]; |
| 216 | this.updateCachedValues(list); |
| 217 | this.emit('resolve', list); |
| 218 | return list; |
| 219 | }); |
| 220 | } else { |
| 221 | // Clone the array so that the cached values won't be mutated |
| 222 | const list = (result = result.filter(v => v != null) as T[]); |
| 223 | this.updateCachedValues(list); |
| 224 | this.emit('resolve', list); |
| 225 | } |
| 226 | return result as ValueOrPromise<T[]>; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Get the list of resolved values. If they are not cached, it tries to find |