MCPcopy
hub / github.com/loopbackio/loopback-next / getValue

Method getValue

packages/context/src/binding.ts:501–570  ·  view source on GitHub ↗
(
    ctx: Context,
    optionsOrSession?: ResolutionOptionsOrSession,
  )

Source from the content-addressed store, hash-verified

499
500 // Implementation
501 getValue(
502 ctx: Context,
503 optionsOrSession?: ResolutionOptionsOrSession,
504 ): ValueOrPromise<T | undefined> {
505 /* istanbul ignore if */
506 if (debug.enabled) {
507 debug('Get value for binding %s', this.key);
508 }
509
510 const options = asResolutionOptions(optionsOrSession);
511 const resolutionCtx = this.getResolutionContext(ctx, options);
512 if (resolutionCtx == null) return undefined;
513
514 // Keep a snapshot for proxy
515 const savedSession =
516 ResolutionSession.fork(options.session) ?? new ResolutionSession();
517
518 // First check cached value for non-transient
519 if (this._cache) {
520 if (this.scope !== BindingScope.TRANSIENT) {
521 if (resolutionCtx && this._cache.has(resolutionCtx)) {
522 const value = this._cache.get(resolutionCtx)!;
523 return this.getValueOrProxy(
524 resolutionCtx,
525 {...options, session: savedSession},
526 value,
527 );
528 }
529 }
530 }
531 const resolutionMetadata = {
532 context: resolutionCtx!,
533 binding: this,
534 options,
535 };
536 if (typeof this._getValue === 'function') {
537 const result = ResolutionSession.runWithBinding(
538 s => {
539 const optionsWithSession = {
540 ...options,
541 session: s,
542 // Force to be the non-proxy version
543 asProxyWithInterceptors: false,
544 };
545 // We already test `this._getValue` is a function. It's safe to assert
546 // that `this._getValue` is not undefined.
547 return this._getValue!({
548 ...resolutionMetadata,
549 options: optionsWithSession,
550 });
551 },
552 this,
553 options.session,
554 );
555 const value = this._cacheValue(resolutionCtx!, result);
556 return this.getValueOrProxy(
557 resolutionCtx,
558 {...options, session: savedSession},

Callers 7

getValueOrPromiseMethod · 0.45
resolveMethod · 0.45
binding.unit.tsFile · 0.45
givenObserversFunction · 0.45

Calls 8

getResolutionContextMethod · 0.95
getValueOrProxyMethod · 0.95
_cacheValueMethod · 0.95
asResolutionOptionsFunction · 0.90
forkMethod · 0.80
runWithBindingMethod · 0.80
rejectMethod · 0.80
getMethod · 0.65

Tested by 1

givenObserversFunction · 0.36