@decaf-ts/db-decorators
Version:
Agnostic database decorators and repository
58 lines (57 loc) • 3.42 kB
TypeScript
import { ConditionalAsync, DecoratorMetadataAsync, Model, ModelConditionalAsync, ValidationPropertyDecoratorDefinition } from "@decaf-ts/decorator-validation";
/**
* @description
* Retrieves validation decorator definitions from a model for update operations, including
* support for special handling of list decorators.
*
* @summary
* Iterates over the model's own enumerable properties and filters out those specified in the
* `propsToIgnore` array. For each remaining property, retrieves validation decorators specific
* to update operations using the `UpdateValidationKeys.REFLECT` key. Additionally, it explicitly
* checks for and appends any `LIST` type decorators to ensure proper validation of collection types.
*
* @template M - A generic parameter extending the `Model` class, representing the model type being inspected.
*
* @param {M} model - The model instance whose properties are being inspected for update-related validations.
* @param {string[]} propsToIgnore - A list of property names to exclude from the validation decorator retrieval process.
*
* @return {ValidationPropertyDecoratorDefinition[]} An array of validation decorator definitions, including both
* update-specific and list-type decorators, excluding those for ignored properties.
*
* @function getValidatableUpdateProps
*/
export declare function getValidatableUpdateProps<M extends Model>(model: M, propsToIgnore: string[]): ValidationPropertyDecoratorDefinition[];
export declare function validateDecorator<M extends Model, Async extends boolean = false>(newModel: M, oldModel: M, prop: string, decorator: DecoratorMetadataAsync, async?: Async): ConditionalAsync<Async, string | undefined>;
export declare function validateDecorators<M extends Model, Async extends boolean = false>(newModel: M, oldModel: M, prop: string, decorators: DecoratorMetadataAsync[], async?: Async): ConditionalAsync<Async, Record<string, string>> | undefined;
/**
* @description Validates changes between two model versions
* @summary Compares an old and new model version to validate update operations
* @template M - Type extending Model
* @param {M} oldModel - The original model version
* @param {M} newModel - The updated model version
* @param {boolean} async - A flag indicating whether validation should be asynchronous.
* @param {...string[]} exceptions - Properties to exclude from validation
* @return {ModelErrorDefinition|undefined} Error definition if validation fails, undefined otherwise
* @function validateCompare
* @memberOf module:db-decorators
* @mermaid
* sequenceDiagram
* participant Caller
* participant validateCompare
* participant Reflection
* participant Validation
*
* Caller->>validateCompare: oldModel, newModel, exceptions
* validateCompare->>Reflection: get decorated properties
* Reflection-->>validateCompare: property decorators
* loop For each decorated property
* validateCompare->>Validation: get validator
* Validation-->>validateCompare: validator
* validateCompare->>validateCompare: validate property update
* end
* loop For nested models
* validateCompare->>validateCompare: validate nested models
* end
* validateCompare-->>Caller: validation errors or undefined
*/
export declare function validateCompare<M extends Model<any>>(oldModel: M, newModel: M, async: boolean, ...exceptions: string[]): ModelConditionalAsync<M>;