@typescript-package/wrap-property
Version:
A lightweight TypeScript package for wrapping object properties.
87 lines (86 loc) • 3.57 kB
TypeScript
import { WrapPropertyCore } from './wrap-property-core.abstract';
import { PropertyControllerShape } from '@typedly/controller';
import { WrappedPropertyDescriptor } from '@typedly/descriptor';
/**
* @description The foundational class for wrapping properties.
* @export
* @abstract
* @class WrapPropertyBase
* @template {Record<PropertyKey, any>} O The type of the object.
* @template {keyof O} [K=keyof O] The key type of the property to wrap.
* @template {boolean} [A=boolean] The type of active property.
* @template {boolean} [F=boolean] The type of enabled property.
* @template {boolean} [C=boolean] The type of configurable property.
* @template {boolean} [E=boolean] The type of enumerable property.
* @template {WrappedPropertyDescriptor<O, K, C, E>} [D=WrappedPropertyDescriptor<O, K, C, E>] The type of descriptor constrained by the `WrappedPropertyDescriptor`.
* @template {PropertyControllerShape<O, K, A, C, E, D>} [R=PropertyControllerShape<O, K, A, C, E, D>] The type of controller that controls the wrapping behavior.
* @extends {WrapPropertyCore<T, O, K, C, E, D, R>}
*/
export declare abstract class WrapPropertyBase<O extends Record<PropertyKey, any>, K extends keyof O = keyof O, A extends boolean = boolean, F extends boolean = boolean, C extends boolean = boolean, E extends boolean = boolean, D extends WrappedPropertyDescriptor<O, K, A, F, C, E> = WrappedPropertyDescriptor<O, K, A, F, C, E>, R extends PropertyControllerShape<O, K, A, F, C, E, D> = PropertyControllerShape<O, K, A, F, C, E, D>> extends WrapPropertyCore<O, K, A, F, C, E, D, R> {
#private;
/**
* @inheritdoc
* @public
* @readonly
* @type {R}
*/
get controller(): R;
/**
* @description The descriptor that handles actual wrapped property.
* @public
* @readonly
* @type {D}
*/
get descriptor(): D;
/**
* @description The key of the property to wrap.
* @protected
* @readonly
* @type {K}
*/
protected get key(): K;
/**
* @description The previous descriptor of the wrapped property.
* @protected
* @readonly
* @type {*}
*/
protected get previousDescriptor(): WrappedPropertyDescriptor<O, K, A, C, E> | PropertyDescriptor | undefined;
/**
* @description The private key used to store the value of the property.
* @protected
* @readonly
* @type {PropertyKey}
*/
protected get privateKey(): PropertyKey;
/**
* @description The target object of the property.
* @protected
* @readonly
* @type {T}
*/
protected get object(): O;
/**
* Creates an instance of `WrapPropertyBase` child class.
* @constructor
* @param {O} object The target object or class to wrap the property of the given `key`.
* @param {K} key The key to wrap the property.
* @param {?D} [descriptor] The descriptor of the property to wrap.
* @param {?new (descriptor?: D) => R} [controller] The controller that controls the wrapping behavior.
*/
constructor(object: O, key: K, descriptor?: D, controller?: new (descriptor?: D) => R);
/**
* @description Unwraps the property using previous descriptor.
* @public
* @returns {this}
*/
unwrap(): this;
/**
* @description Wraps the property with a private indicator.
* @protected
* @param {O} object The object to wrap the property on.
* @param {K} key The key of the property to wrap.
* @returns {this}
*/
protected wrap(object: O, key: K): this;
}