A descriptor that holds metadata information for classes, properties, methods, and parameters.
class MetadataDescriptor { constructor(name?: string); description?: string; example?: any; label?: string; labelPlural?: string; name?: string; noun?: string; nounPlural?: string; sensitive?: boolean; token?: string; tokenPlural?: string; static for(target: object | Class, property?: string, index?: number): MetadataDescriptor; static get(target: object | Class, property?: string, index?: number): undefined | MetadataDescriptor;}MetadataDescriptorCreates a new MetadataDescriptor instance.
stringMetadataDescriptorstringA detailed description of the decorated element. Descriptions provide additional context and information about the purpose and usage of the decorated element.
anyAn example value for the decorated element. Examples can be used in documentation, validation messages, or as default values in user interfaces.
stringA human-readable label for the decorated element. Labels are typically used in user interfaces such as form inputs, tables, and auto-generated documentation.
stringThe plural form of the label. Used when displaying multiple instances of the decorated element, such as in table headers or list titles.
stringThe name of the decorated element. For classes, this is typically the class name. For properties, this is typically the property name. For parameters, this is usually undefined unless explicitly set.
stringA noun that represents the decorated element. Nouns are used for grammatical purposes and can help with generating proper text in documentation or user interfaces.
stringThe plural form of the noun. Used when referring to multiple instances of the decorated element.
booleanIndicates whether the decorated element contains sensitive information. When true, this element should be treated with special care in terms of logging, serialization, and display to ensure sensitive data is not inadvertently exposed.
stringA token identifier for the decorated element. Tokens are typically used for internal identification and can be used for serialization or other programmatic operations.
stringThe plural form of the token. Used when referring to multiple instances of the decorated element.
MetadataDescriptorGets or creates a MetadataDescriptor for the specified target.
object | ClassstringnumberMetadataDescriptorundefined | MetadataDescriptorRetrieves an existing MetadataDescriptor for the specified target.
object | Classstringnumberundefined | MetadataDescriptorA descriptor that holds metadata information for classes, properties, methods, and parameters.
The MetadataDescriptor class is used to store and retrieve metadata associated with various
elements in your codebase. It supports storing information like names, labelPlural, descriptions,
and other metadata that can be used for serialization, validation, documentation generation,
and other metadata-driven operations.
// create a get descriptor for a class
const descriptor = MetaDataDescriptor.for(MyClass);
// create or get a descriptor for a property or method
const descriptor = MetaDataDescriptor.for(MyClass, 'myProperty');
// create or get adescriptor for a method parameter
const descriptor = MetaDataDescriptor.for(MyClass, 'myMethod', 0);
// get descriptor for a class
const descriptor = MetaDataDescriptor.get(MyClass);
// get descriptor for a property or method
const descriptor = MetaDataDescriptor.get(MyClass, 'myProperty');
// get descriptor for a method parameter
const descriptor = MetaDataDescriptor.get(MyClass, 'myMethod', 0);
class User {
@Label('Email address')
@Description('The user\'s email address')
@Sensitive()
email: string;
@Label('Full name')
fullName: string;
}
// Get metadata for the class
const classDescriptor = MetadataDescriptor.for(User);
console.log(classDescriptor.name); // 'User'
// Get metadata for the email property
const emailDescriptor = MetadataDescriptor.for(User, 'email');
console.log(emailDescriptor.label); // 'Email Address'
console.log(emailDescriptor.sensitive); // true
