admin-bro
Version:
Admin panel for apps written in node.js
111 lines (110 loc) • 3.57 kB
TypeScript
/**
* @typedef {string} PropertyType
* @memberof BaseProperty
* @alias PropertyType
* @property {string} string default property type
* @property {string} float type of floating point numbers
* @property {string} number regular number
* @property {string} boolean boolean value
* @property {string} date date
* @property {string} datetime date with time
* @property {string} mixed type representing an object
* @property {string} reference many to one reference
*/
export declare type PropertyType = 'string' | 'float' | 'number' | 'boolean' | 'date' | 'datetime' | 'mixed' | 'reference';
/**
* Represents Resource Property
* @category Base
*/
declare class BaseProperty {
private _path;
private _type;
private _isId;
private _isSortable;
/**
* @param {object} options
* @param {string} options.path property path: usually it its key but when
* property is for an object the path can be
* divided to parts by dots: i.e.
* 'address.street'
* @param {string} [options.type='string'] one if: string, float, number, boolean, date
* @param {boolean} [options.isId=false] true when field should be treated as an ID
* @param {boolean} [options.isSortable=true] if property should be sortable
*/
constructor({ path, type, isId, isSortable }: {
path: string;
type?: PropertyType;
isId?: boolean;
isSortable?: boolean;
});
/**
* Name of the property
* @return {string} name of the property
*/
name(): string;
path(): string;
/**
* Return type of a property
* @return {PropertyType}
*/
type(): PropertyType;
/**
* Return true if given property should be treated as a Record Title.
*
* @return {boolean}
*/
isTitle(): boolean;
/**
* Indicates if given property should be visible
*
* @return {Boolean}
*/
isVisible(): boolean;
/**
* Indicates if value of given property can be updated
*
* @return {boolean}
*/
isEditable(): boolean;
/**
* Returns true if given property is a uniq key in a table/collection
*
* @return {boolean}
*/
isId(): boolean;
/**
* If property is a reference to a record of different resource
* it should contain {@link BaseResource.id} of this resource.
*
* When property is responsible for the field: 'user_id' in SQL database
* reference should be the name of the Resource which it refers to: `Users`
*/
reference(): string | null;
/**
* Returns all available values which field can accept. It is used in case of
* enums
*
* @return {Array<String> | null} array of all available values or null when field
* is not an enum.
*/
availableValues(): Array<string> | null;
/**
* Returns true when given property is an array
*
* @return {boolean}
*/
isArray(): boolean;
/**
* In case of `mixed` type returns all nested properties.
*
* @return {Array<BaseProperty>} sub properties
*/
subProperties(): Array<BaseProperty>;
/**
* Indicates if given property can be sorted
*
* @return {boolean}
*/
isSortable(): boolean;
}
export default BaseProperty;