How to use the @loopback/metadata.MetadataAccessor.create function in @loopback/metadata

To help you get started, we’ve selected a few @loopback/metadata 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 / authentication / src / keys.ts View on Github external
*/
  export const METADATA = BindingKey.create(
    'authentication.operationMetadata',
  );

  export const AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME =
    'authentication.strategies';

  // Make `CURRENT_USER` the alias of SecurityBindings.USER for backward compatibility
  export const CURRENT_USER = SecurityBindings.USER;
}

/**
 * The key used to store method-level metadata for `@authenticate`
 */
export const AUTHENTICATION_METADATA_METHOD_KEY = MetadataAccessor.create<
  AuthenticationMetadata,
  MethodDecorator
>('authentication:method');

/**
 * Alias for AUTHENTICATION_METADATA_METHOD_KEY to keep it backward compatible
 */
export const AUTHENTICATION_METADATA_KEY = AUTHENTICATION_METADATA_METHOD_KEY;

/**
 * The key used to store class-level metadata for `@authenticate`
 */
export const AUTHENTICATION_METADATA_CLASS_KEY = MetadataAccessor.create<
  AuthenticationMetadata,
  ClassDecorator
>('authentication:class');
github strongloop / loopback-next / packages / context / src / inject.ts View on Github external
BindingFilter,
  BindingSelector,
  filterByTag,
  isBindingAddress,
} from './binding-filter';
import {BindingAddress} from './binding-key';
import {BindingComparator} from './binding-sorter';
import {BindingCreationPolicy, Context} from './context';
import {ContextView, createViewGetter} from './context-view';
import {ResolutionOptions, ResolutionSession} from './resolution-session';
import {BoundValue, ValueOrPromise} from './value-promise';

const PARAMETERS_KEY = MetadataAccessor.create(
  'inject:parameters',
);
const PROPERTIES_KEY = MetadataAccessor.create(
  'inject:properties',
);

// A key to cache described argument injections
const METHODS_KEY = MetadataAccessor.create(
  'inject:methods',
);

/**
 * A function to provide resolution of injected values
 */
export interface ResolverFunction {
  (
    ctx: Context,
    injection: Readonly,
    session: ResolutionSession,
github strongloop / loopback-next / packages / context / src / inject.ts View on Github external
} from '@loopback/metadata';
import {Binding, BindingTag} from './binding';
import {
  BindingFilter,
  BindingSelector,
  filterByTag,
  isBindingAddress,
} from './binding-filter';
import {BindingAddress} from './binding-key';
import {BindingComparator} from './binding-sorter';
import {BindingCreationPolicy, Context} from './context';
import {ContextView, createViewGetter} from './context-view';
import {ResolutionOptions, ResolutionSession} from './resolution-session';
import {BoundValue, ValueOrPromise} from './value-promise';

const PARAMETERS_KEY = MetadataAccessor.create(
  'inject:parameters',
);
const PROPERTIES_KEY = MetadataAccessor.create(
  'inject:properties',
);

// A key to cache described argument injections
const METHODS_KEY = MetadataAccessor.create(
  'inject:methods',
);

/**
 * A function to provide resolution of injected values
 */
export interface ResolverFunction {
  (
github strongloop / loopback-next / packages / context / src / inject.ts View on Github external
import {BindingAddress} from './binding-key';
import {BindingComparator} from './binding-sorter';
import {BindingCreationPolicy, Context} from './context';
import {ContextView, createViewGetter} from './context-view';
import {ResolutionOptions, ResolutionSession} from './resolution-session';
import {BoundValue, ValueOrPromise} from './value-promise';

const PARAMETERS_KEY = MetadataAccessor.create(
  'inject:parameters',
);
const PROPERTIES_KEY = MetadataAccessor.create(
  'inject:properties',
);

// A key to cache described argument injections
const METHODS_KEY = MetadataAccessor.create(
  'inject:methods',
);

/**
 * A function to provide resolution of injected values
 */
export interface ResolverFunction {
  (
    ctx: Context,
    injection: Readonly,
    session: ResolutionSession,
  ): ValueOrPromise;
}

/**
 * An object to provide metadata for `@inject`
github strongloop / loopback-next / packages / context / src / interceptor.ts View on Github external
for (const i of interceptorsToApply) {
    if (appliedInterceptors.has(i)) {
      interceptorsToApply.delete(i);
    }
  }
  // Add existing interceptors after ones from the spec
  for (const i of appliedInterceptors) {
    interceptorsToApply.add(i);
  }
  return Array.from(interceptorsToApply);
}

/**
 * Metadata key for method-level interceptors
 */
export const INTERCEPT_CLASS_KEY = MetadataAccessor.create<
  InterceptorOrKey[],
  ClassDecorator
>('intercept:class');

/**
 * A factory to define `@intercept` for classes. It allows `@intercept` to be
 * used multiple times on the same class.
 */
class InterceptClassDecoratorFactory extends ClassDecoratorFactory<
  InterceptorOrKey[]
> {
  protected mergeWithOwn(ownMetadata: InterceptorOrKey[], target: Object) {
    ownMetadata = ownMetadata || [];
    return mergeInterceptors(this.spec, ownMetadata);
  }
}
github sourcefuse / loopback4-authorization / src / keys.ts View on Github external
export const METADATA = BindingKey.create(
    'sf.userAuthorization.operationMetadata',
  );

  export const USER_PERMISSIONS = BindingKey.create>(
    'sf.userAuthorization.actions.userPermissions',
  );

  export const CONFIG = BindingKey.create(
    'sf.userAuthorization.config',
  );

  export const PATHS_TO_ALLOW_ALWAYS = 'sf.userAuthorization.allowAlways';
}

export const AUTHORIZATION_METADATA_ACCESSOR = MetadataAccessor.create<
  AuthorizationMetadata,
  MethodDecorator
>('sf.userAuthorization.accessor.operationMetadata');
github strongloop / loopback-next / packages / repository-json-schema / src / keys.ts View on Github external
import {JSONSchema6 as JSONSchema} from 'json-schema';

/**
 * TODO(semver-major) remove these constants in the next major version
 * @deprecated Use the helper `buildModelCacheKey` to obtain the cache key
 * for a given set of schema options.
 */
export const enum MODEL_TYPE_KEYS {
  ModelOnly = 'modelOnly',
  ModelWithRelations = 'modelWithRelations',
}

/**
 * Metadata key used to set or retrieve repository JSON Schema
 */
export const JSON_SCHEMA_KEY = MetadataAccessor.create<
  {[key: string]: JSONSchema},
  ClassDecorator
>('loopback:json-schema');
github strongloop / loopback-next / packages / context / src / interceptor.ts View on Github external
/**
 * Interceptor function to intercept method invocations
 */
export interface Interceptor extends GenericInterceptor {}

/**
 * Interceptor function or binding key that can be used as parameters for
 * `@intercept()`
 */
export type InterceptorOrKey = GenericInterceptorOrKey;

/**
 * Metadata key for method-level interceptors
 */
export const INTERCEPT_METHOD_KEY = MetadataAccessor.create<
  InterceptorOrKey[],
  MethodDecorator
>('intercept:method');

/**
 * Adding interceptors from the spec to the front of existing ones. Duplicate
 * entries are eliminated from the spec side.
 *
 * For example:
 *
 * - [log] + [cache, log] => [cache, log]
 * - [log] + [log, cache] => [log, cache]
 * - [] + [cache, log] => [cache, log]
 * - [cache, log] + [] => [cache, log]
 * - [log] + [cache] => [log, cache]
 *
github strongloop / loopback-next / packages / context / src / binding-inspector.ts View on Github external
*/
export type BindingMetadata = {
  /**
   * An array of template functions to configure a binding
   */
  templates: BindingTemplate[];
  /**
   * The target class where binding metadata is decorated
   */
  target: Constructor;
};

/**
 * Metadata key for binding metadata
 */
export const BINDING_METADATA_KEY = MetadataAccessor.create<
  BindingMetadata,
  ClassDecorator
>('binding.metadata');

/**
 * An object to configure binding scope and tags
 */
export type BindingScopeAndTags = {
  scope?: BindingScope;
  tags?: BindingTag | BindingTag[];
};

/**
 * Specification of parameters for `@bind()`
 */
export type BindingSpec = BindingTemplate | BindingScopeAndTags;
github strongloop / loopback-next / packages / authentication / src / keys.ts View on Github external
* The key used to store method-level metadata for `@authenticate`
 */
export const AUTHENTICATION_METADATA_METHOD_KEY = MetadataAccessor.create<
  AuthenticationMetadata,
  MethodDecorator
>('authentication:method');

/**
 * Alias for AUTHENTICATION_METADATA_METHOD_KEY to keep it backward compatible
 */
export const AUTHENTICATION_METADATA_KEY = AUTHENTICATION_METADATA_METHOD_KEY;

/**
 * The key used to store class-level metadata for `@authenticate`
 */
export const AUTHENTICATION_METADATA_CLASS_KEY = MetadataAccessor.create<
  AuthenticationMetadata,
  ClassDecorator
>('authentication:class');