MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / inspectInjection

Function inspectInjection

packages/context/src/inject.ts:747–779  ·  view source on GitHub ↗

* Inspect an injection * @param injection - Injection information

(injection: Readonly<Injection<unknown>>)

Source from the content-addressed store, hash-verified

745 * @param injection - Injection information
746 */
747function inspectInjection(injection: Readonly<Injection<unknown>>) {
748 const injectionInfo = ResolutionSession.describeInjection(injection);
749 const descriptor: JSONObject = {};
750 if (injectionInfo.targetName) {
751 descriptor.targetName = injectionInfo.targetName;
752 }
753 if (isBindingAddress(injectionInfo.bindingSelector)) {
754 // Binding key
755 descriptor.bindingKey = injectionInfo.bindingSelector.toString();
756 } else if (isBindingTagFilter(injectionInfo.bindingSelector)) {
757 // Binding tag filter
758 descriptor.bindingTagPattern = JSON.parse(
759 JSON.stringify(injectionInfo.bindingSelector.bindingTagPattern),
760 );
761 } else {
762 // Binding filter function
763 descriptor.bindingFilter =
764 injectionInfo.bindingSelector?.name ?? '<function>';
765 }
766 // Inspect metadata
767 if (injectionInfo.metadata) {
768 if (
769 injectionInfo.metadata.decorator &&
770 injectionInfo.metadata.decorator !== '@inject'
771 ) {
772 descriptor.decorator = injectionInfo.metadata.decorator;
773 }
774 if (injectionInfo.metadata.optional) {
775 descriptor.optional = injectionInfo.metadata.optional;
776 }
777 }
778 return descriptor;
779}
780
781/**
782 * Check if the given class has `@inject` or other decorations that map to

Callers 1

inspectInjectionsFunction · 0.85

Calls 5

isBindingAddressFunction · 0.90
isBindingTagFilterFunction · 0.90
describeInjectionMethod · 0.80
parseMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected