The Magic
The magic library is a decorator to define custom behavior for classes in Typescript.
Usage
It's easy to use just before coding set "experimentalDecorators": true
in tsconfig.json
and wirte your classes like bellow example:
import Magic from "@botstan/magic";
@Magic
export class MyClass
{
[key: string]: any;
/**
* The __isset() method is called when code calls
* `name in $instance` or `if ($instance[name])` on a
* property that is not accessible. It accepts one
* argument, which is the name of the property. It
* should return a Boolean value representing the
* existence of a value.
*
* @param {string} name
* @returns {boolean}
*/
public __isset (name: string): boolean
{
}
/**
* The __unset() method is called when code attempts to
* `delete $instance[name]` a property that is not
* accessible. It accepts one argument, which is the
* name of the property.
*
* @param {string} name
* @returns {void}
*/
public __unset (name: string): void
{
}
/**
* The __set() method is called when code attempts to
* change the value a property that is not accessible.
* It accepts two arguments, which are the name of the
* property and the value.
*
* @param {string} name
* @param {*} value
* @returns {void}
*/
public __set (name: string, value: any): void
{
}
/**
* The __get() method is called when code attempt
* access a property that is not accessible. It accepts
* one argument, which is the name of the property. It
* should return a value, which will be treated as the
* value of the property.
*
* @param {string} name
* @returns {*}
*/
public __get (name: string): any
{
}
/**
* The __call() is called when code attempts to call
* inaccessible or nonexistent methods. It accepts
* three arguments: the action name, the name of the
* called method and an array of arguments.
*
* @param {string} action
* @param {string} name
* @param {object} args
* @returns {(boolean | void)}
*/
public __call (action: string, name: string, args: object): any
{
}
/**
* The __issetStatic() method is called when code calls
* `name in $class` or `if ($class[name])` on a
* static property that is not accessible. It accepts
* one argument, which is the name of the property. It
* should return a Boolean value representing the
* existence of a value.
*
* @param {string} name
* @returns {boolean}
*/
public __issetStatic (name): boolean
{
}
/**
* The __unsetStatic() method is called when code
* attempts to `delete $class[name]` a static property
* that is not accessible. It accepts one argument,
* which is the name of the property.
*
* @param {string} name
* @returns {void}
*/
public __unsetStatic (name): void
{
}
/**
* The __set() method is called when code attempts to
* change the value a static property that is not
* accessible. It accepts two arguments, which are the
* name of the property and the value.
*
* @param {string} name
* @param {*} value
* @returns {void}
*/
public __setStatic (name, value): void
{
}
/**
* The __getStatic() method is called when code attempt
* access a static property that is not accessible. It
* accepts one argument, which is the name of the
* property. It should return a value, which will be
* treated as the value of the property.
*
* @param {string} name
* @returns {*}
*/
public __getStatic (name): any
{
}
/**
* The __call() is called when code attempts to call
* inaccessible or nonexistent static methods. It
* accepts three arguments: the action name, the name
* of the called method and an array of arguments.
*
* @param {string} action
* @param {string} name
* @param {object} args
* @returns {(boolean | void)}
*/
public __callStatic (action: string, name: string, args: object): any
{
}
}