Class

Reflection

Reflection(annotationPrefix, target, propertyName, ignoreTypeopt, recursiveopt, accumulatoropt)

Constructor

# new Reflection(annotationPrefix, target, propertyName, ignoreTypeopt, recursiveopt, accumulatoropt)

Namespace class holding reflection API that provides functionality to handle reflection metadata, type checking, and decorator management

A utility class for handling reflection metadata in TypeScript

sequenceDiagram participant Client participant Reflection participant ReflectAPI Client->>Reflection: getAllPropertyDecorators(model, prefix) Reflection->>Reflection: getPropertyDecorators(prefix, model, propKey) Reflection->>ReflectAPI: getMetadataKeys(target, propertyName) ReflectAPI-->>Reflection: keys[] Reflection->>ReflectAPI: getMetadata(key, target, propertyName) ReflectAPI-->>Reflection: metadata Reflection-->>Client: decorators
Parameters:
Name Type Attributes Description
annotationPrefix string

The prefix used to filter decorators in various methods

target object

The target object or class to retrieve metadata from

propertyName string | symbol

The name of the property to retrieve metadata for

ignoreType boolean <optional>

Whether to ignore type metadata in certain operations

recursive boolean <optional>

Whether to recursively traverse the prototype chain

accumulator Array.<DecoratorMetadata> <optional>

Used to accumulate metadata during recursive operations

View Source Reflection.ts, line 4

Example
// Get all property decorators with a specific prefix
const model = new MyClass();
const decorators = Reflection.getAllPropertyDecorators(model, 'prefix');

// Check if a value matches a specific type
const isString = Reflection.checkTypes(value, ['string']);

// Get all properties of an object including inherited ones
const props = Reflection.getAllProperties(obj, true);

// Get class decorators with a specific prefix
const classDecorators = Reflection.getClassDecorators('prefix', myClassInstance);

// Get property type from decorator
const propType = Reflection.getTypeFromDecorator(model, 'propertyName');

Methods

# static checkType(value, acceptedType) → {boolean}

Utility function to verify if a value's type matches the provided type name

Checks if a value matches a specified type name

Parameters:
Name Type Description
value unknown

The value to check the type of

acceptedType string

The type name to check against

View Source Reflection.ts, line 53

Returns true if the value matches the accepted type, false otherwise

boolean

# static checkTypes(value, acceptedTypes) → {boolean}

Utility function to verify if a value's type matches any of the provided type names

Checks if a value matches any of the specified type names

Parameters:
Name Type Description
value unknown

The value to check the type of

acceptedTypes Array.<string>

Array of type names to check against

View Source Reflection.ts, line 293

Returns true if the value matches any of the accepted types, false otherwise

boolean

# static evaluateDesignTypes(value, types) → {boolean}

Compares a value against type metadata to determine if they match

Evaluates if a value matches the specified type metadata

Parameters:
Name Type Description
value unknown

The value to evaluate

types string | Array.<string> | Object

Type metadata to check against, can be a string, array of strings, or an object with a name property

View Source Reflection.ts, line 302

Returns true if the value matches the type metadata, false otherwise

boolean

# static getAllProperties(obj, climbTreeopt, stopAtopt) → {Array.<string>}

Collects all property names from an object, optionally including those from its prototype chain

Retrieves all properties of an object

Parameters:
Name Type Attributes Default Description
obj Record.<string, unknown>

The object to retrieve properties from

climbTree boolean <optional>
true

Whether to crawl up the prototype chain

stopAt string <optional>
"Object"

The constructor name at which to stop climbing the prototype chain

View Source Reflection.ts, line 312

An array of all property names found in the object

Array.<string>

# static getAllPropertyDecorators(model, prefixes) → {Record.<string, Array.<DecoratorMetadata>>|undefined}

Collects all decorators for an object's properties that start with any of the provided prefixes

Retrieves all property decorators with specific prefixes for an object

Parameters:
Name Type Description
model M

The object to retrieve property decorators from

prefixes Array.<string>

Array of prefixes to filter decorators by

View Source Reflection.ts, line 331

A record mapping property names to their decorators, or undefined if none found

Record.<string, Array.<DecoratorMetadata>> | undefined

# static getClassDecorators(annotationPrefix, target) → {ClassDecoratorsList}

Utility function to extract class-level decorators that start with a given prefix

Retrieves all class decorators with a specific prefix

Parameters:
Name Type Description
annotationPrefix string

The prefix to filter decorators by

target object

The class instance to retrieve decorators from

View Source Reflection.ts, line 321

An array of objects containing decorator keys and their properties

ClassDecoratorsList

# static getPropertyDecorators(annotationPrefix, target, propertyName, ignoreTypeopt, recursiveopt, accumulatoropt) → {FullPropertyDecoratorList}

Utility function to extract property-level decorators that start with a given prefix, with options for recursive prototype chain traversal

Retrieves all decorators for a specific property

sequenceDiagram participant Client participant Reflection participant InnerFunction participant ReflectAPI Client->>Reflection: getPropertyDecorators(prefix, target, propName) Reflection->>InnerFunction: getPropertyDecoratorsForModel(prefix, target, propName) InnerFunction->>ReflectAPI: getMetadataKeys(target, propertyName) ReflectAPI-->>InnerFunction: keys[] InnerFunction->>ReflectAPI: getMetadata(key, target, propertyName) ReflectAPI-->>InnerFunction: metadata InnerFunction-->>Reflection: {prop, decorators} alt recursive && not Object.prototype Reflection->>Reflection: getPropertyDecorators(prefix, prototype, propName, true, recursive, result.decorators) else Reflection->>Reflection: trim(result.decorators) end Reflection-->>Client: {prop, decorators}
Parameters:
Name Type Attributes Default Description
annotationPrefix string

The prefix to filter decorators by

target object

The object containing the property

propertyName string | symbol

The name of the property to retrieve decorators for

ignoreType boolean <optional>
false

Whether to ignore the TYPE metadata key

recursive boolean <optional>
true

Whether to climb the prototype chain looking for more decorators

accumulator Array.<DecoratorMetadata> <optional>

Used internally to accumulate decorators during recursive calls

View Source Reflection.ts, line 375

An object containing the property name and its decorators

FullPropertyDecoratorList

# static getTypeFromDecorator(model, propKey) → {string|undefined}

Extracts the type information from a property's decorator metadata

Uses metadata to discover the type of a property from its decorator

Parameters:
Name Type Description
model object

The object containing the property

propKey string | symbol

The key of the property to get the type for

View Source Reflection.ts, line 340

The type name of the property, or undefined if not found or if the type is Function

string | undefined