How to use the @nestjs/core/metadata-scanner.MetadataScanner function in @nestjs/core

To help you get started, we’ve selected a few @nestjs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github notadd / nt-module-user / test / user-module / app.module.ts View on Github external
constructor(
        @Inject(ModulesContainer) private readonly modulesContainer: ModulesContainer,
        @InjectRepository(Resource) private readonly resourceRepo: Repository,
        @InjectRepository(Permission) private readonly permissionRepo: Repository,

    ) {
        this.metadataScanner = new MetadataScanner();
    }
github nestjs / nest / bundle / microservices / listeners-controller.js View on Github external
constructor(clientsContainer, contextCreator) {
        this.clientsContainer = clientsContainer;
        this.contextCreator = contextCreator;
        this.metadataExplorer = new listener_metadata_explorer_1.ListenerMetadataExplorer(new metadata_scanner_1.MetadataScanner());
    }
    bindPatternHandlers(instance, server, module) {
github notadd / nt-module-user / package / user.module.js View on Github external
constructor(userService, modulesContainer, systemModuleRepo, resourceRepo, permissionRepo, roleRepo, infoGroupRepo, userRepo) {
        this.userService = userService;
        this.modulesContainer = modulesContainer;
        this.systemModuleRepo = systemModuleRepo;
        this.resourceRepo = resourceRepo;
        this.permissionRepo = permissionRepo;
        this.roleRepo = roleRepo;
        this.infoGroupRepo = infoGroupRepo;
        this.userRepo = userRepo;
        this.metadataScanner = new metadata_scanner_1.MetadataScanner();
    }
    static forRoot(options) {
github adrien2p / nestjs-dialogflow / src / core / scanner.ts View on Github external
public scanAndRegisterHandlers(): void {
		const metadataScanner = new MetadataScanner();
		const modules = [...this.modulesContainer.values()];

		modules.forEach(({ metatype }) => {
			const metadata = Reflect.getMetadata(nestMetadata.COMPONENTS, metatype) || [];
			const providers = [...metadata.filter((metatype: any) => typeof metatype === 'function')];

			providers.map(provider => {
				metadataScanner.scanFromPrototype(null, provider.prototype, methodName => {
					const intentOrAction =
						Reflect.getMetadata(
							DIALOG_FLOW_INTENT,
							Reflect.getOwnPropertyDescriptor(provider.prototype, methodName).value,
						) ||
						Reflect.getMetadata(
							DIALOG_FLOW_ACTION,
							Reflect.getOwnPropertyDescriptor(provider.prototype, methodName).value,
github nestjsx / nestjs-braintree / src / braintree.webhook.module.ts View on Github external
providers.map(provider => {
        if (Reflect.getOwnMetadata(BRAINTREE_WEBHOOK_PROVIDER, provider)) {

          const realProvider = this.moduleRef.get(provider, {strict: false});

          this.braintreeWebhookProvider.addProvider(realProvider);

          const metadataScanner = new MetadataScanner();

          metadataScanner.scanFromPrototype(null, provider['prototype'], method => {
            const descriptor = Reflect.getOwnPropertyDescriptor(
              provider['prototype'],
              method,
            );

            const hook = Reflect.getMetadata(BRAINTREE_WEBHOOK_METHOD, descriptor.value);

            if (hook) {
              this.braintreeWebhookProvider.addMethod(hook, method, realProvider.constructor.name);
            }
          });

        }
      });
github nestjs / nest / src / microservices / listeners-controller.ts View on Github external
import 'reflect-metadata';
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface';
import { ListenerMetadataExplorer } from './listener-metadata-explorer';
import { Server } from './server/server';
import { ClientProxyFactory } from './client/client-proxy-factory';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { CustomTransportStrategy } from './interfaces';
import { ClientsContainer } from './container';
import { RpcContextCreator } from './context/rpc-context-creator';

export class ListenersController {
    private readonly metadataExplorer = new ListenerMetadataExplorer(new MetadataScanner());

    constructor(
        private readonly clientsContainer: ClientsContainer,
        private readonly contextCreator: RpcContextCreator) {}

    public bindPatternHandlers(instance: Controller, server: Server & CustomTransportStrategy, module: string) {
        const patternHandlers = this.metadataExplorer.explore(instance);
        patternHandlers.forEach(({ pattern, targetCallback }) => {
            const proxy = this.contextCreator.create(instance, targetCallback, module);
            server.add(pattern, proxy);
        });
    }

    public bindClientsToProperties(instance: Controller) {
        for (const { property, metadata } of this.metadataExplorer.scanForClientHooks(instance)) {
            const client = ClientProxyFactory.create(metadata);
github nestjs / nest / bundle / websockets / web-sockets-controller.js View on Github external
constructor(socketServerProvider, container, config, contextCreator) {
        this.socketServerProvider = socketServerProvider;
        this.container = container;
        this.config = config;
        this.contextCreator = contextCreator;
        this.metadataExplorer = new gateway_metadata_explorer_1.GatewayMetadataExplorer(new metadata_scanner_1.MetadataScanner());
        this.middlewareInjector = new middleware_injector_1.MiddlewareInjector(container, config);
    }
    hookGatewayIntoServer(instance, metatype, module) {
github nestjs / nest / src / websockets / web-sockets-controller.ts View on Github external
InvalidSocketPortException
} from './exceptions/invalid-socket-port.exception';
import {
  GatewayMetadataExplorer,
  MessageMappingProperties
} from './gateway-metadata-explorer';
import {NestGateway} from './interfaces/nest-gateway.interface';
import {
  ObservableSocketServer
} from './interfaces/observable-socket-server.interface';
import {MiddlewaresInjector} from './middlewares-injector';
import {SocketServerProvider} from './socket-server-provider';

export class WebSocketsController {
  private readonly metadataExplorer =
      new GatewayMetadataExplorer(new MetadataScanner());
  private readonly middlewaresInjector: MiddlewaresInjector;

  constructor(
      private readonly socketServerProvider: SocketServerProvider,
      private readonly container: NestContainer,
      private readonly config: ApplicationConfig,
      private readonly contextCreator: WsContextCreator,
  ) {
    this.middlewaresInjector = new MiddlewaresInjector(container, config);
  }

  public hookGatewayIntoServer(instance: NestGateway,
                               metatype: Metatype, module: string) {
    const namespace = Reflect.getMetadata(NAMESPACE_METADATA, metatype) || '';
    const port = Reflect.getMetadata(PORT_METADATA, metatype) || 0;
github nestjs / nest / lib / microservices / listeners-controller.js View on Github external
constructor(clientsContainer, contextCreator) {
        this.clientsContainer = clientsContainer;
        this.contextCreator = contextCreator;
        this.metadataExplorer = new listener_metadata_explorer_1.ListenerMetadataExplorer(new metadata_scanner_1.MetadataScanner());
    }
    bindPatternHandlers(instance, server, module) {
github erickponce / nestjs-kue / src / module / services / kue / kue-task-register.service.ts View on Github external
constructor(private readonly kueService: KueService) {
        this.metadataExplorer = new TaskMetadataExplorer(
            new MetadataScanner()
        );
        this.fancyLogger = new FancyLoggerService();
    }