@smartsoft001/models
TypeScript icon, indicating that this package has built-in type declarations

2.48.0 • Public • Published

Decorators

@Model Decorator

Used to annotate a class as a "model," adding metadata and a custom toJSON method. This method serializes the instance into JSON format, including fields marked with specific metadata. Associates the model with metadata (IModelOptions) using reflection, allowing for dynamic handling of models at runtime.

@Field Decorator

Used to annotate properties of a model class, providing additional metadata (IFieldOptions) such as field type, requirements, and custom behavior for serialization or validation. Defines how properties should be accessed, mutated, and serialized, including special handling for arrays and specific types.

Utility Functions

Metadata Retrieval

Functions like getModelFieldKeys, getModelFieldOptions, getModelFieldsWithOptions, and getModelOptions are used to retrieve metadata about models and their fields. This enables dynamic inspection and manipulation of models.

Model Validation

getInvalidFields - Checks for fields that have invalid values based on specified rules (such as being required during "create" or "update" operations) and permissions. This is useful for form validation or API input validation.

Model Casting

castModel - Adjusts an instance of a model by removing fields that do not conform to the specified mode ("create", "update") or the provided permissions. This ensures the instance is valid and adheres to the constraints defined by the model's metadata.

Model Check

isModel - Determines if an object is a model decorated with the @Model decorator.

Readme

Keywords

none

Package Sidebar

Install

npm i @smartsoft001/models

Weekly Downloads

130

Version

2.48.0

License

none

Unpacked Size

17.5 kB

Total Files

16

Last publish

Collaborators

  • emiljuchnikowski