@decaf-ts/db-decorators
Version:
Agnostic database decorators and repository
46 lines (45 loc) • 2 kB
TypeScript
import { Model } from "@decaf-ts/decorator-validation";
/**
* @description Checks if a model is marked as transient
* @summary Determines whether a model class has been decorated with the transient decorator
* @template M - Type extending Model
* @param {M} model - The model instance to check
* @return {boolean} True if the model is transient, false otherwise
* @function isTransient
* @memberOf module:db-decorators
*/
export declare function isTransient<M extends Model>(model: M): boolean;
/**
* @description Separates transient properties from a model
* @summary Extracts properties marked as transient into a separate object
* @template M - Type extending Model
* @param {M} model - The model instance to process
* @return {Object} Object containing the model without transient properties and a separate transient object
* @property {M} model - The model with transient properties removed
* @property {Record<string, any>} [transient] - Object containing the transient properties
* @function modelToTransient
* @memberOf module:db-decorators
* @mermaid
* sequenceDiagram
* participant Caller
* participant modelToTransient
* participant isTransient
* participant getAllPropertyDecoratorsRecursive
*
* Caller->>modelToTransient: model
* modelToTransient->>isTransient: check if model is transient
* isTransient-->>modelToTransient: transient status
* alt model is not transient
* modelToTransient-->>Caller: {model}
* else model is transient
* modelToTransient->>getAllPropertyDecoratorsRecursive: get transient properties
* getAllPropertyDecoratorsRecursive-->>modelToTransient: property decorators
* modelToTransient->>modelToTransient: separate properties
* modelToTransient->>Model.build: rebuild model without transient props
* modelToTransient-->>Caller: {model, transient}
* end
*/
export declare function modelToTransient<M extends Model>(model: M): {
model: M;
transient?: Record<string, any>;
};