Models API
TypeScript decorators for property metadata extraction and model introspection.
What It Does
The Models API provides a lightweight decorator system for marking model properties and extracting property names at runtime. It enables reflection-based model introspection without complex metadata libraries.
Key Capabilities
- Property Decoration:
@property()decorator for marking properties - Metadata Extraction: Extract decorated property names at runtime
- Reflection Support: Built on reflect-metadata
- Type Safety: Full TypeScript support
- Minimal Overhead: Lightweight decorator implementation
Main Export
@property() Decorator
function property(target: any, key: string): voidMarks a property for metadata tracking. Used in conjunction with getProperties().
getProperties() Function
function getProperties(target: any): string[]Extracts all property names decorated with @property().
Usage Pattern
import {property, getProperties} from '@engineering11/models'
class UserModel {
@property
id: string
@property
email: string
@property
name: string
// Not decorated
privateField: string
}
// Extract decorated properties
const props = getProperties(UserModel.prototype)
// Returns: ['id', 'email', 'name']Common Use Cases
- Dynamic property extraction for forms
- Selective serialization
- Schema generation
- Validation frameworks
- ORM property mapping
What Customers Don’t Have to Build
- Property decorator infrastructure
- Metadata reflection system
- Property name extraction
- Decorator-based introspection
Last updated on