How to use the @loopback/context.MetadataAccessor.create 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 / authorization / src / decorators / authorize.ts View on Github external
MethodDecoratorFactory,
} from '@loopback/context';
import {
  AUTHENTICATED,
  AuthorizationMetadata,
  Authorizer,
  EVERYONE,
  UNAUTHENTICATED,
} from '../types';

export const AUTHORIZATION_METHOD_KEY = MetadataAccessor.create<
  AuthorizationMetadata,
  MethodDecorator
>('authorization:method');

export const AUTHORIZATION_CLASS_KEY = MetadataAccessor.create<
  AuthorizationMetadata,
  ClassDecorator
>('authorization:class');

class AuthorizeClassDecoratorFactory extends ClassDecoratorFactory<
  AuthorizationMetadata
> {}

export class AuthorizeMethodDecoratorFactory extends MethodDecoratorFactory<
  AuthorizationMetadata
> {
  protected mergeWithOwn(
    ownMetadata: MetadataMap,
    target: Object,
    methodName?: string,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
github strongloop / loopback-next / packages / service-proxy / src / decorators / service.decorator.ts View on Github external
import {
  MetadataAccessor,
  inject,
  Context,
  Injection,
  InjectionMetadata,
} from '@loopback/context';
import {getService, juggler} from '..';

/**
 * Type definition for decorators returned by `@serviceProxy` decorator factory
 */
export type ServiceProxyDecorator = PropertyDecorator | ParameterDecorator;

export const SERVICE_PROXY_KEY = MetadataAccessor.create<
  string,
  ServiceProxyDecorator
>('service.proxy');

/**
 * Metadata for a service proxy
 */
export class ServiceProxyMetadata implements InjectionMetadata {
  decorator = '@serviceProxy';
  dataSourceName?: string;
  dataSource?: juggler.DataSource;

  constructor(dataSource: string | juggler.DataSource) {
    if (typeof dataSource === 'string') {
      this.dataSourceName = dataSource;
    } else {
github strongloop / loopback-next / packages / repository / src / decorators / model.decorator.ts View on Github external
ClassDecoratorFactory,
  MetadataAccessor,
  MetadataInspector,
  MetadataMap,
  PropertyDecoratorFactory,
} from '@loopback/context';
import {
  ModelDefinition,
  ModelDefinitionSyntax,
  PropertyDefinition,
  PropertyType,
  RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';

export const MODEL_KEY = MetadataAccessor.create<
  Partial,
  ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
  PropertyDefinition,
  PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
  ModelDefinition,
  ClassDecorator
>('loopback:model-and-properties');

export type PropertyMap = MetadataMap;

/**
 * Decorator for model definitions
github strongloop / loopback-next / packages / repository / src / decorators / model.decorator.ts View on Github external
PropertyDecoratorFactory,
} from '@loopback/context';
import {
  ModelDefinition,
  ModelDefinitionSyntax,
  PropertyDefinition,
  PropertyType,
  RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';

export const MODEL_KEY = MetadataAccessor.create<
  Partial,
  ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
  PropertyDefinition,
  PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
  ModelDefinition,
  ClassDecorator
>('loopback:model-and-properties');

export type PropertyMap = MetadataMap;

/**
 * Decorator for model definitions
 * @param definition
 * @returns A class decorator for `model`
 */
export function model(definition?: Partial) {
github raymondfeng / loopback4-example-websocket / src / decorators / websocket.decorator.ts View on Github external
import {
  ClassDecoratorFactory,
  Constructor,
  MetadataAccessor,
  MetadataInspector,
  MethodDecoratorFactory,
  inject,
} from '@loopback/context';

export interface WebSocketMetadata {
  namespace?: string | RegExp;
}

export const WEBSOCKET_METADATA = MetadataAccessor.create<
  WebSocketMetadata,
  ClassDecorator
>('websocket');

/**
 * Decorate a websocket controller class to specify the namespace
 * For example,
 * ```ts
 * @ws({namespace: '/chats'})
 * export class WebSocketController {}
 * ```
 * @param spec A namespace or object
 */
export function ws(spec: WebSocketMetadata | string | RegExp = {}) {
  if (typeof spec === 'string' || spec instanceof RegExp) {
    spec = {namespace: spec};
github strongloop / loopback-next / packages / repository / src / decorators / model.decorator.ts View on Github external
ModelDefinitionSyntax,
  PropertyDefinition,
  PropertyType,
  RelationDefinitionMap,
} from '../model';
import {RELATIONS_KEY} from '../relations/relation.decorator';

export const MODEL_KEY = MetadataAccessor.create<
  Partial,
  ClassDecorator
>('loopback:model');
export const MODEL_PROPERTIES_KEY = MetadataAccessor.create<
  PropertyDefinition,
  PropertyDecorator
>('loopback:model-properties');
export const MODEL_WITH_PROPERTIES_KEY = MetadataAccessor.create<
  ModelDefinition,
  ClassDecorator
>('loopback:model-and-properties');

export type PropertyMap = MetadataMap;

/**
 * Decorator for model definitions
 * @param definition
 * @returns A class decorator for `model`
 */
export function model(definition?: Partial) {
  return function(target: Function & {definition?: ModelDefinition}) {
    definition = definition ?? {};
    const def: ModelDefinitionSyntax = Object.assign(definition, {
      name: definition.name ?? target.name,
github strongloop / loopback-next / packages / authorization / src / decorators / authorize.ts View on Github external
ClassDecoratorFactory,
  DecoratorFactory,
  MetadataAccessor,
  MetadataInspector,
  MetadataMap,
  MethodDecoratorFactory,
} from '@loopback/context';
import {
  AUTHENTICATED,
  AuthorizationMetadata,
  Authorizer,
  EVERYONE,
  UNAUTHENTICATED,
} from '../types';

export const AUTHORIZATION_METHOD_KEY = MetadataAccessor.create<
  AuthorizationMetadata,
  MethodDecorator
>('authorization:method');

export const AUTHORIZATION_CLASS_KEY = MetadataAccessor.create<
  AuthorizationMetadata,
  ClassDecorator
>('authorization:class');

class AuthorizeClassDecoratorFactory extends ClassDecoratorFactory<
  AuthorizationMetadata
> {}

export class AuthorizeMethodDecoratorFactory extends MethodDecoratorFactory<
  AuthorizationMetadata
> {