UNPKG

@decaf-ts/decorator-validation

Version:
47 lines (46 loc) 2.22 kB
import { Model } from "./Model"; /** * @description Helper function to create an instance by invoking a constructor with dynamic arguments. * @summary Overrides standard construction patterns by wrapping the given constructor to allow spread argument invocation while preserving the prototype chain. * @template M the model instance type * @param {any} constructor The constructor function to invoke. * @param {...any[]} args Optional arguments to pass to the constructor. * @return {M} The newly constructed instance. * @function construct * @memberOf module:decorator-validation */ export declare function construct<M extends Model>(constructor: any, ...args: any[]): M; /** * @description Recursively finds the last prototype in the chain before reaching Object.prototype. * @summary Walks up the prototype chain to locate the most derived prototype that still precedes the base Object prototype. * @param {object} obj The object whose prototype chain will be inspected. * @return {object} The last prototype before Object.prototype, or the input object if its prototype is Object.prototype. * @function findLastProtoBeforeObject * @memberOf module:decorator-validation */ export declare function findLastProtoBeforeObject(obj: object): object; /** * @description Binds the Model class as the root prototype of the provided instance when not already a Model. * @summary Ensures objects created outside of the Model inheritance chain gain Model as their ultimate prototype to access model utilities. * @param {unknown} obj The object to bind to the Model prototype chain. * @return {void} * @function bindModelPrototype * @mermaid * sequenceDiagram * participant Caller * participant Fn as bindModelPrototype * participant M as Model.prototype * Caller->>Fn: obj * alt obj instanceof Model * Fn-->>Caller: return * else obj chain ends at Object.prototype * Fn->>Fn: setPrototypeOf(obj, M) * Fn-->>Caller: return * else deep prototype chain * Fn->>Fn: walk prototypes * Fn->>Fn: setPrototypeOf(last, M) * Fn-->>Caller: return * end * @memberOf module:decorator-validation */ export declare function bindModelPrototype(obj: unknown): void;