跳到主要内容
版本:Next

MetadataManager

A class that manages metadata for classes and properties This class is a simplified version of the Reflect Metadata API Provides a way to retrieve, define, delete and copy metadata

@since

4.0.0

Index

Constructors

constructor

Properties

publicstaticObjectType

ObjectType: typeof ObjectType = ObjectType

publicstaticreadonlyemptyValueSymbol

emptyValueSymbol: typeof emptyValueSymbol = ...

A symbol that represents an empty value

Methods

publicstaticattachMetadata

  • attachMetadata(metadataKey: string | symbol, metadataValue: any, target: object | ClassType, propertyKey?: string | symbol): void
  • Attaches metadata for a target class or property Value will push to the end of the metadata array and save for own metadata

publicstaticcopyMetadata

  • copyMetadata(source: ClassType, target: ClassType, options?: { metadataFilter?: (metadataKey: string | symbol, propertyKey?: string | symbol) => boolean; overwrite?: boolean }): void
  • Copies metadata from a source class or property to a target class or property

publicstaticcopyOwnMetadata

  • copyOwnMetadata(source: ClassType, target: ClassType, options?: { metadataFilter?: (metadataKey: string | symbol, propertyKey?: string | symbol) => boolean; overwrite?: boolean }): void
  • Copies own metadata from a source class or property to a target class or property

publicstaticdefineMetadata

  • defineMetadata(metadataKey: string | symbol, metadataValue: any, target: object | ClassType, propertyKey?: string | symbol): void
  • Defines metadata for a target class or property Value will replace the existing metadata

publicstaticdeleteMetadata

  • deleteMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): void
  • Deletes metadata for a target class or property

publicstaticensureTargetType

  • ensureTargetType(target: any, type: ObjectType): void

publicstaticgetMetadata

  • getMetadata<T>(metadataKey: string | symbol, target: object | ClassType, propertyKey?: string | symbol): T
  • Retrieves metadata for a target class or property


    Type parameters

    • T = any

publicstaticgetMetadataKeys

  • getMetadataKeys(target: ClassType, propertyKey?: string | symbol): string[]
  • Get all metadata keys on the entire prototype chain Because we need to get metadata on the entire prototype chain, we do not use cache here, so the performance is poor

publicstaticgetMethodParamTypes

  • getMethodParamTypes(target: ClassType, methodName: string | symbol, parameterIndex?: number): any
  • Get parameters type by reflect-metadata

publicstaticgetMethodReturnTypes

  • getMethodReturnTypes(target: ClassType, propertyKey: string | symbol): any
  • Gets the type of a property from Reflect metadata

publicstaticgetOwnMetadata

  • getOwnMetadata<T>(metadataKey: string | symbol, target: object | ClassType, propertyKey?: string | symbol): T
  • Retrieves own metadata for a target class or property


    Type parameters

    • T = any

publicstaticgetOwnMetadataKeys

  • getOwnMetadataKeys(target: ClassType, propertyKey?: string | symbol): string[]
  • Get metadata keys on the current class or object

publicstaticgetOwnPropertiesWithMetadata

  • getOwnPropertiesWithMetadata<T>(metadataKey: string | symbol, target: ClassType): {}
  • Retrieves all properties of the current class that have a specific metadata key and their metadata values.


    Type parameters

    • T = any

publicstaticgetPropertiesWithMetadata

  • getPropertiesWithMetadata<T>(metadataKey: string | symbol, target: ClassType): {}
  • Retrieves all properties of the class and its prototype chain that have a specific metadata key and their metadata values.


    Type parameters

    • T = any

publicstaticgetPropertyType

  • getPropertyType(target: ClassType, propertyKey: string | symbol): any
  • Get property(method) type from metadata

publicstatichasMetadata

  • hasMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): boolean
  • Checks if metadata exists for a target class or property

publicstatichasOwnMetadata

  • hasOwnMetadata(metadataKey: string | symbol, target: ClassType, propertyKey?: string | symbol): boolean
  • Checks if own metadata exists for a target class or property

publicstatictransformTypeFromTSDesign

  • transformTypeFromTSDesign(designFn: any): TSDesignType<unknown>