2022-03-23 14:46:19 +00:00
|
|
|
/**
|
|
|
|
* # Schema
|
|
|
|
*
|
|
|
|
* Main purpose of this is to describe the shape of the Models table in the
|
|
|
|
* database. But there is some irrelevant information in the schemas with
|
|
|
|
* respect to this goal. This is information is allowed as long as it is not
|
|
|
|
* dynamic, which is impossible anyways as the files are data (.json !.js)
|
|
|
|
*
|
|
|
|
* If any field has to have a dynamic value, it should be added to the controller
|
|
|
|
* file by the same name.
|
|
|
|
*
|
|
|
|
* There are a few types of schemas:
|
|
|
|
* - _Regional_: Schemas that are in the '../regional' subdirectories
|
|
|
|
* these can be of any of the below types.
|
|
|
|
* - _Abstract_: Schemas that are not used as they are but only after they are
|
|
|
|
* extended by Stub schemas. Indentified by the `isAbstract` field
|
|
|
|
* - _Subclass_: Schemas that have an "extends" field on them, the value of which
|
|
|
|
* points to an Abstract schema.
|
|
|
|
* - _Complete_: Schemas which are neither abstract nor stub.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* ## Final Schema
|
|
|
|
*
|
|
|
|
* This is the schema which is used by the database and app code.
|
|
|
|
*
|
|
|
|
* The order in which a schema is built is:
|
|
|
|
* 1. Build _Regional_ schemas by overriding the fields and other properties of the
|
|
|
|
* non regional variants.
|
|
|
|
* 2. Combine _Subclass_ schemas with _Abstract_ schemas to get complete schemas.
|
|
|
|
*
|
|
|
|
* Note: if a Regional schema is not present as a non regional variant it's used
|
|
|
|
* as it is.
|
2022-03-28 10:01:29 +00:00
|
|
|
*
|
|
|
|
* ## Additional Notes
|
|
|
|
*
|
|
|
|
* In all the schemas, the 'name' field/column is the primary key. If it isn't
|
|
|
|
* explicitly added, the schema builder will add it in.
|
2022-03-23 14:46:19 +00:00
|
|
|
*/
|
|
|
|
|
2022-03-23 08:37:00 +00:00
|
|
|
export enum FieldTypeEnum {
|
|
|
|
Data = 'Data',
|
|
|
|
Select = 'Select',
|
|
|
|
Link = 'Link',
|
|
|
|
Date = 'Date',
|
2022-03-31 11:43:20 +00:00
|
|
|
Datetime = 'Datetime',
|
2022-03-23 08:37:00 +00:00
|
|
|
Table = 'Table',
|
|
|
|
AutoComplete = 'AutoComplete',
|
|
|
|
Check = 'Check',
|
|
|
|
AttachImage = 'AttachImage',
|
|
|
|
DynamicLink = 'DynamicLink',
|
|
|
|
Int = 'Int',
|
|
|
|
Float = 'Float',
|
|
|
|
Currency = 'Currency',
|
|
|
|
Text = 'Text',
|
|
|
|
Color = 'Color',
|
|
|
|
Code = 'Code',
|
|
|
|
}
|
|
|
|
|
|
|
|
export type FieldType = keyof typeof FieldTypeEnum;
|
2022-03-31 09:04:30 +00:00
|
|
|
export type RawValue = string | number | boolean | null;
|
2022-03-23 08:37:00 +00:00
|
|
|
|
|
|
|
export interface BaseField {
|
2022-03-23 14:46:19 +00:00
|
|
|
fieldname: string; // Column name in the db
|
|
|
|
fieldtype: FieldType; // UI Descriptive field types that map to column types
|
|
|
|
label: string; // Translateable UI facing name
|
|
|
|
required?: boolean; // Implies Not Null
|
|
|
|
hidden?: boolean; // UI Facing config, whether field is shown in a form
|
|
|
|
readOnly?: boolean; // UI Facing config, whether field is editable
|
|
|
|
description?: string; // UI Facing, translateable, used for inline documentation
|
|
|
|
default?: RawValue; // Default value of a field, should match the db type
|
|
|
|
placeholder?: string; // UI Facing config, form field placeholder
|
|
|
|
groupBy?: string; // UI Facing used in dropdowns fields
|
|
|
|
computed?: boolean; // Indicates whether a value is computed, implies readonly
|
2022-03-23 16:40:36 +00:00
|
|
|
meta?: boolean; // Field is a meta field, i.e. only for the db, not UI
|
2022-04-01 09:35:51 +00:00
|
|
|
inline?: boolean; // UI Facing config, whether to display doc inline.
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type SelectOption = { value: string; label: string };
|
|
|
|
export interface OptionField extends BaseField {
|
|
|
|
fieldtype:
|
|
|
|
| FieldTypeEnum.Select
|
|
|
|
| FieldTypeEnum.AutoComplete
|
|
|
|
| FieldTypeEnum.Color;
|
|
|
|
options: SelectOption[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TargetField extends BaseField {
|
|
|
|
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
|
2022-03-24 09:50:40 +00:00
|
|
|
target: string; // Name of the table or group of tables to fetch values
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface DynamicLinkField extends BaseField {
|
|
|
|
fieldtype: FieldTypeEnum.DynamicLink;
|
2022-03-23 14:46:19 +00:00
|
|
|
references: string; // Reference to an option field that links to schema
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface NumberField extends BaseField {
|
|
|
|
fieldtype: FieldTypeEnum.Float | FieldTypeEnum.Int;
|
2022-03-23 14:46:19 +00:00
|
|
|
minvalue?: number; // UI Facing used to restrict lower bound
|
|
|
|
maxvalue?: number; // UI Facing used to restrict upper bound
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Field =
|
|
|
|
| BaseField
|
|
|
|
| OptionField
|
|
|
|
| TargetField
|
|
|
|
| DynamicLinkField
|
|
|
|
| NumberField;
|
|
|
|
|
|
|
|
export type TreeSettings = { parentField: string };
|
2022-03-23 14:46:19 +00:00
|
|
|
|
2022-03-23 08:37:00 +00:00
|
|
|
export interface Schema {
|
2022-03-28 10:01:29 +00:00
|
|
|
name: string; // Table name
|
2022-03-23 14:46:19 +00:00
|
|
|
label: string; // Translateable UI facing name
|
|
|
|
fields: Field[]; // Maps to database columns
|
|
|
|
isTree?: boolean; // Used for nested set, eg for Chart of Accounts
|
|
|
|
extends?: string; // Value points to an Abstract schema. Indicates Subclass schema
|
|
|
|
isChild?: boolean; // Indicates a child table, i.e table with "parent" FK column
|
|
|
|
isSingle?: boolean; // Fields will be values in SingleValue, i.e. an Entity Attr. Value
|
|
|
|
isAbstract?: boolean; // Not entered into db, used to extend a Subclass schema
|
2022-03-28 10:01:29 +00:00
|
|
|
tableFields?: string[] // Used for displaying childTableFields
|
2022-03-23 14:46:19 +00:00
|
|
|
isSubmittable?: boolean; // For transactional types, values considered only after submit
|
2022-03-25 12:32:37 +00:00
|
|
|
keywordFields?: string[]; // Used to get fields that are to be used for search.
|
|
|
|
quickEditFields?: string[]; // Used to get fields for the quickEditForm
|
2022-03-23 14:46:19 +00:00
|
|
|
treeSettings?: TreeSettings; // Used to determine root nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SchemaStub extends Partial<Schema> {
|
2022-03-23 08:37:00 +00:00
|
|
|
name: string;
|
|
|
|
}
|
2022-03-23 14:46:19 +00:00
|
|
|
export type SchemaMap = Record<string, Schema>;
|
|
|
|
export type SchemaStubMap = Record<string, SchemaStub>;
|