MCPcopy
hub / github.com/nestjs/nest / collectDeepServices

Method collectDeepServices

packages/microservices/server/server-grpc.ts:669–705  ·  view source on GitHub ↗

* Recursively fetch all of the service methods available on loaded * protobuf descriptor object, and collect those as an objects with * dot-syntax full-path names. * * Example: * for proto package Bundle.FirstService with service Events { rpc... * will be resolved to object of (w

(
    name: string,
    grpcDefinition: any,
    accumulator: { name: string; service: any }[],
  )

Source from the content-addressed store, hash-verified

667 * }
668 */
669 private collectDeepServices(
670 name: string,
671 grpcDefinition: any,
672 accumulator: { name: string; service: any }[],
673 ) {
674 if (!isObject(grpcDefinition)) {
675 return;
676 }
677 const keysToTraverse = Object.keys(grpcDefinition);
678 // Traverse definitions or namespace extensions
679 for (const key of keysToTraverse) {
680 const nameExtended = this.parseDeepServiceName(name, key);
681 const deepDefinition = grpcDefinition[key];
682
683 const isServiceDefined =
684 deepDefinition && !isUndefined(deepDefinition.service);
685 const isServiceBoolean = isServiceDefined
686 ? deepDefinition.service !== false
687 : false;
688
689 // grpc namespace object does not have 'format' or 'service' properties defined
690 const isFormatDefined =
691 deepDefinition && !isUndefined(deepDefinition.format);
692
693 if (isServiceDefined && isServiceBoolean) {
694 accumulator.push({
695 name: nameExtended,
696 service: deepDefinition,
697 });
698 } else if (isFormatDefined) {
699 // Do nothing
700 } else {
701 // Continue recursion for namespace object until objects end or service definition found
702 this.collectDeepServices(nameExtended, deepDefinition, accumulator);
703 }
704 }
705 }
706
707 private parseDeepServiceName(name: string, key: string): string {
708 // If depth is zero then just return key

Callers 1

getServiceNamesMethod · 0.95

Calls 3

parseDeepServiceNameMethod · 0.95
isObjectFunction · 0.90
isUndefinedFunction · 0.90

Tested by

no test coverage detected