Class: classdecoratorfactory = new ClassDecoratorFactory()

Factory for class decorators

create() : ClassDecorator

createDecorator(key: string, spec: T, options: DecoratorOptions) :

Create a class decorator function

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator

Class: decoratorfactory = new DecoratorFactory()

Base factory class for decorator functions

Properties
Name Type Description
TARGET string

A constant to reference the target of a decoration

constructor(key: string, spec: T, options: DecoratorOptions) : DecoratorFactory

Construct a new class decorator factory

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator. Default to
{allowInheritance: true} if not provided

create() : D

Create a decorator function of the given type. Each sub class MUST
implement this method.

getTarget(spec: T) : any

Get the optional decoration target of a given spec

Arguments
Name Type Description
spec T

Metadata spec

withTarget(spec: T, target: Object) : T

Set a reference to the target class or prototype for a given spec if
it's an object

Arguments
Name Type Description
spec T

Metadata spec

target Object

Target of the decoration. It is a class or the prototype of
a class.

cloneDeep(val: T) : T

Arguments
Name Type Description
val T

Base factory class for decorator functions

getNumberOfParameters(target: Object, member: undefined) : number

Get the number of parameters for a given constructor or method

Arguments
Name Type Description
target Object

Class or the prototype

member

Method name

getTargetName(target: Object, member: undefined, descriptorOrIndex: undefined) : string

Get the qualified name of a decoration target. For example:

class MyClass
MyClass.constructor[0] // First parameter of the constructor
MyClass.myStaticProperty
MyClass.myStaticMethod()
MyClass.myStaticMethod[0] // First parameter of the myStaticMethod
MyClass.prototype.myProperty
MyClass.prototype.myMethod()
MyClass.prototype.myMethod[1] // Second parameter of myMethod

Arguments
Name Type Description
target Object

Class or prototype of a class

member

Optional property/method name

descriptorOrIndex

Optional method descriptor or parameter index

Class: methoddecoratorfactory = new MethodDecoratorFactory()

Factory for method decorators

create() : MethodDecorator

createDecorator(key: string, spec: T, options: DecoratorOptions) :

Create a method decorator function

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator

Class: methodparameterdecoratorfactory = new MethodParameterDecoratorFactory()

Factory for method level parameter decorator. For example, the following
code uses @param to declare two parameters for greet().

class MyController {
  @param('name') // Parameter 0
  @param('msg')  // Parameter 1
  greet() {}
}

create() : MethodDecorator

createDecorator(key: string, spec: T, options: DecoratorOptions) :

Create a method decorator function

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator

Class: parameterdecoratorfactory = new ParameterDecoratorFactory()

Factory for parameter decorators

create() : ParameterDecorator

createDecorator(key: string, spec: T, options: DecoratorOptions) :

Create a parameter decorator function

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator

Class: propertydecoratorfactory = new PropertyDecoratorFactory()

Factory for property decorators

create() : PropertyDecorator

createDecorator(key: string, spec: T, options: DecoratorOptions) :

Create a property decorator function

Arguments
Name Type Description
key string

Metadata key

spec T

Metadata object from the decorator function

options DecoratorOptions

Options for the decorator

Interface: DecoratorOptions

Options for a decorator

Properties
Name Type Description
allowInheritance boolean

Controls if inherited metadata will be honored. Default to true.

cloneInputSpec boolean

Controls if the value of spec argument will be cloned. Sometimes we
use shared spec for the decoration, but the decorator function might need
to mutate the object. Cloning the input spec makes it safe to use the same
spec (template) to decorate different members.

Default to true.

Interface: MetadataMap

An object mapping keys to corresponding metadata

Class: metadatainspector = new MetadataInspector()

Inspector for metadata applied by decorators

Properties
Name Type Description
DesignTimeReflector NamespacedReflect

Expose the reflector for TypeScript design-time metadata

Reflector NamespacedReflect

Expose Reflector, which is a wrapper of Reflect and it uses loopback
as the namespace prefix for all metadata keys

defineMetadata(key: string, value: T, target: Object, member: undefined) : void

Define metadata for the given target

Arguments
Name Type Description
key string

Metadata key

value T

Metadata value

target Object

Target for the metadata

member

Optional property or method name

getAllMethodMetadata(key: string, target: Object, options: InspectionOptions) : MetadataMap | undefined

Get the metadata associated with the given key for all methods of the
target class or prototype

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static methods or prototype for instance methods

options InspectionOptions

Options for inspection

getAllParameterMetadata(key: string, target: Object, methodName: undefined, options: InspectionOptions) : undefined | undefined

Get the metadata associated with the given key for all parameters of a
given method

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static methods or prototype for instance methods

methodName

Method name. If not present, default to '' to use
the constructor

options InspectionOptions

Options for inspection

getAllPropertyMetadata(key: string, target: Object, options: InspectionOptions) : MetadataMap | undefined

Get the metadata associated with the given key for all properties of the
target class or prototype

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static methods or prototype for instance methods

options InspectionOptions

Options for inspection

getClassMetadata(key: string, target: Function, options: InspectionOptions) : T | undefined

Get the metadata associated with the given key for a given class

Arguments
Name Type Description
key string

Metadata key

target Function

Class that contains the metadata

options InspectionOptions

Options for inspection

getDesignTypeForMethod(target: Object, methodName: undefined) : DesignTimeMethodMetadata

Get TypeScript design time type for a method

Arguments
Name Type Description
target Object

Class or prototype

methodName

Method name

getDesignTypeForProperty(target: Object, propertyName: undefined) : Function

Get TypeScript design time type for a property

Arguments
Name Type Description
target Object

Class or prototype

propertyName

Property name

getMethodMetadata(key: string, target: Object, methodName: undefined, options: InspectionOptions) : T | undefined

Get the metadata associated with the given key for a given method of the
target class or prototype

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static methods or prototype for instance methods

methodName

Method name. If not present, default to '' to use
the constructor

options InspectionOptions

Options for inspection

getParameterMetadata(key: string, target: Object, methodName: undefined, index: number, options: InspectionOptions) : T | undefined

Get the metadata associated with the given key for a parameter of a given
method by index

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static methods or prototype for instance methods

methodName

Method name. If not present, default to '' to use
the constructor

index number

Index of the parameter, starting with 0

options InspectionOptions

Options for inspection

getPropertyMetadata(key: string, target: Object, propertyName: undefined, options: InspectionOptions) : T | undefined

Get the metadata associated with the given key for a given property of the
target class or prototype

Arguments
Name Type Description
key string

Metadata key

target Object

Class for static properties or prototype for instance
properties

propertyName

Property name

options InspectionOptions

Options for inspection

Interface: DesignTimeMethodMetadata

Design time metadata for a method.

Properties
Name Type Description
parameterTypes

An array of parameter types

returnType Function

Return type

type Function

Type of the method itself. It is Function

Interface: InspectionOptions

Options for inspection

Properties
Name Type Description
ownMetadataOnly boolean

Only inspect own metadata of a given target. The prototype chain will not
be checked. The implementation uses Reflect.getOwnMetadata() if the flag
is set to true. Otherwise, it uses Reflect.getMetadata().

The flag is false by default for MetadataInspector.

Class: namespacedreflect = new NamespacedReflect()

constructor(namespace: string) : NamespacedReflect

Arguments
Name Type Description
namespace string

: namespace to bind this reflect context

decorate(decorators: undefined, target: Object, targetKey: undefined, descriptor: PropertyDescriptor) : PropertyDescriptor | Function

Arguments
Name Type Description
decorators
target Object
targetKey
descriptor PropertyDescriptor

defineMetadata(metadataKey: string, metadataValue: any, target: Object, propertyKey: undefined) : void

define metadata for a target class or it's property/method

Arguments
Name Type Description
metadataKey string
metadataValue any
target Object
propertyKey

deleteMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getMetadata(metadataKey: string, target: Object, propertyKey: undefined) : any

lookup metadata from a target object and its prototype chain

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getMetadataKeys(target: Object, propertyKey: undefined) :

Arguments
Name Type Description
target Object
propertyKey

getOwnMetadata(metadataKey: string, target: Object, propertyKey: undefined) : any

get own metadata for a target object or it's property/method

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

getOwnMetadataKeys(target: Object, propertyKey: undefined) :

Arguments
Name Type Description
target Object
propertyKey

hasMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Check if the target has corresponding metadata

Arguments
Name Type Description
metadataKey string

Key

target Object

Target

propertyKey

Optional property key

hasOwnMetadata(metadataKey: string, target: Object, propertyKey: undefined) : boolean

Arguments
Name Type Description
metadataKey string
target Object
propertyKey

metadata(metadataKey: string, metadataValue: any) :

Arguments
Name Type Description
metadataKey string
metadataValue any