How to use the @loopback/context.MetadataInspector.getAllMethodMetadata function in @loopback/context

To help you get started, we’ve selected a few @loopback/context 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 strongloop / loopback-next / packages / openapi-v2 / src / controller-spec.ts View on Github external
function resolveControllerSpec(constructor: Function): ControllerSpec {
  debug(`Retrieving OpenAPI specification for controller ${constructor.name}`);

  let spec = MetadataInspector.getClassMetadata(
    OAI2Keys.CLASS_KEY,
    constructor,
  );
  if (spec) {
    debug('  using class-level spec defined via @api()', spec);
    spec = DecoratorFactory.cloneDeep(spec);
  } else {
    spec = {paths: {}};
  }

  let endpoints =
    MetadataInspector.getAllMethodMetadata(
      OAI2Keys.METHODS_KEY,
      constructor.prototype,
    ) || {};

  endpoints = DecoratorFactory.cloneDeep(endpoints);
  for (const op in endpoints) {
    debug('  processing method %s', op);

    const endpoint = endpoints[op];
    const verb = endpoint.verb!;
    const path = endpoint.path!;

    let endpointName = '';
    /* istanbul ignore if */
    if (debug.enabled) {
      const className = constructor.name || '';
github raymondfeng / loopback4-example-websocket / src / websocket-controller-factory.ts View on Github external
registerSubscribeMethods(socket: Socket) {
    const regexpEventHandlers = new Map<
      RegExp[],
      (...args: unknown[]) => Promise
    >();
    const subscribeMethods =
      MetadataInspector.getAllMethodMetadata<(string | RegExp)[]>(
        'websocket:subscribe',
        this.controllerClass.prototype,
      ) || {};
    for (const m in subscribeMethods) {
      for (const t of subscribeMethods[m]) {
        const regexps: RegExp[] = [];
        if (typeof t === 'string') {
          socket.on(t, async (...args: unknown[]) => {
            await invokeMethod(this.controller, m, this.ctx, args);
          });
        } else if (t instanceof RegExp) {
          regexps.push(t);
        }
        if (regexps.length) {
          // Build a map of regexp based message handlers
          regexpEventHandlers.set(regexps, async (...args: unknown[]) => {
github raymondfeng / loopback4-example-websocket / src / websocket-controller-factory.ts View on Github external
async connect(socket: Socket) {
    const connectMethods =
      MetadataInspector.getAllMethodMetadata(
        'websocket:connect',
        this.controllerClass.prototype,
      ) || {};
    for (const m in connectMethods) {
      await invokeMethod(this.controller, m, this.ctx, [socket]);
    }
  }