Type schema fields
This commit is contained in:
parent
088ed1139c
commit
fe6535a65f
|
@ -1,6 +1,11 @@
|
||||||
import { objectStore, roles, constants } from "@budibase/backend-core"
|
import { objectStore, roles, constants } from "@budibase/backend-core"
|
||||||
import { FieldType as FieldTypes } from "@budibase/types"
|
import { FieldType as FieldTypes } from "@budibase/types"
|
||||||
export { FieldType as FieldTypes, RelationshipType } from "@budibase/types"
|
export {
|
||||||
|
FieldType as FieldTypes,
|
||||||
|
RelationshipType,
|
||||||
|
AutoFieldSubTypes,
|
||||||
|
FormulaTypes,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
export enum FilterTypes {
|
export enum FilterTypes {
|
||||||
STRING = "string",
|
STRING = "string",
|
||||||
|
@ -39,11 +44,6 @@ export const SwitchableTypes = CanSwitchTypes.reduce((prev, current) =>
|
||||||
prev ? prev.concat(current) : current
|
prev ? prev.concat(current) : current
|
||||||
)
|
)
|
||||||
|
|
||||||
export enum FormulaTypes {
|
|
||||||
STATIC = "static",
|
|
||||||
DYNAMIC = "dynamic",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum AuthTypes {
|
export enum AuthTypes {
|
||||||
APP = "app",
|
APP = "app",
|
||||||
BUILDER = "builder",
|
BUILDER = "builder",
|
||||||
|
@ -132,14 +132,6 @@ export const USERS_TABLE_SCHEMA = {
|
||||||
primaryDisplay: "email",
|
primaryDisplay: "email",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutoFieldSubTypes {
|
|
||||||
CREATED_BY = "createdBy",
|
|
||||||
CREATED_AT = "createdAt",
|
|
||||||
UPDATED_BY = "updatedBy",
|
|
||||||
UPDATED_AT = "updatedAt",
|
|
||||||
AUTO_ID = "autoID",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum AutoFieldDefaultNames {
|
export enum AutoFieldDefaultNames {
|
||||||
CREATED_BY = "Created By",
|
CREATED_BY = "Created By",
|
||||||
CREATED_AT = "Created At",
|
CREATED_AT = "Created At",
|
||||||
|
|
|
@ -7,3 +7,16 @@ export enum RelationshipType {
|
||||||
export enum AutoReason {
|
export enum AutoReason {
|
||||||
FOREIGN_KEY = "foreign_key",
|
FOREIGN_KEY = "foreign_key",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AutoFieldSubTypes {
|
||||||
|
CREATED_BY = "createdBy",
|
||||||
|
CREATED_AT = "createdAt",
|
||||||
|
UPDATED_BY = "updatedBy",
|
||||||
|
UPDATED_AT = "updatedAt",
|
||||||
|
AUTO_ID = "autoID",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum FormulaTypes {
|
||||||
|
STATIC = "static",
|
||||||
|
DYNAMIC = "dynamic",
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
// all added by grid/table when defining the
|
// all added by grid/table when defining the
|
||||||
// column size, position and whether it can be viewed
|
// column size, position and whether it can be viewed
|
||||||
import { FieldType } from "../row"
|
import { FieldType } from "../row"
|
||||||
import { AutoReason, RelationshipType } from "./constants"
|
import {
|
||||||
|
AutoFieldSubTypes,
|
||||||
|
AutoReason,
|
||||||
|
FormulaTypes,
|
||||||
|
RelationshipType,
|
||||||
|
} from "./constants"
|
||||||
|
|
||||||
export interface UIFieldMetadata {
|
export interface UIFieldMetadata {
|
||||||
order?: number
|
order?: number
|
||||||
|
@ -10,20 +15,25 @@ export interface UIFieldMetadata {
|
||||||
icon?: string
|
icon?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RelationshipFieldMetadata {
|
interface ManyToManyRelationshipFieldMetadata {
|
||||||
|
relationshipType: RelationshipType.MANY_TO_MANY
|
||||||
|
through: string
|
||||||
|
throughFrom: string
|
||||||
|
throughTo: string
|
||||||
|
}
|
||||||
|
interface OneSidedRelationshipFieldMetadata {
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY | RelationshipType.MANY_TO_ONE
|
||||||
|
foreignKey: string
|
||||||
|
}
|
||||||
|
export type RelationshipFieldMetadata = BaseFieldSchema & {
|
||||||
|
type: FieldType.LINK
|
||||||
main?: boolean
|
main?: boolean
|
||||||
fieldName?: string
|
fieldName?: string
|
||||||
tableId?: string
|
tableId: string
|
||||||
// below is used for SQL relationships, needed to define the foreign keys
|
} & (ManyToManyRelationshipFieldMetadata | OneSidedRelationshipFieldMetadata)
|
||||||
// or the tables used for many-to-many relationships (through)
|
|
||||||
relationshipType?: RelationshipType
|
|
||||||
through?: string
|
|
||||||
foreignKey?: string
|
|
||||||
throughFrom?: string
|
|
||||||
throughTo?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AutoColumnFieldMetadata {
|
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||||
|
type: FieldType.AUTO
|
||||||
autocolumn?: boolean
|
autocolumn?: boolean
|
||||||
subtype?: string
|
subtype?: string
|
||||||
lastID?: number
|
lastID?: number
|
||||||
|
@ -31,7 +41,10 @@ export interface AutoColumnFieldMetadata {
|
||||||
autoReason?: AutoReason
|
autoReason?: AutoReason
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NumberFieldMetadata {
|
interface NumberForeignKeyMetadata {
|
||||||
|
subtype: AutoFieldSubTypes.AUTO_ID
|
||||||
|
autoReason: AutoReason.FOREIGN_KEY
|
||||||
|
autocolumn: true
|
||||||
// used specifically when Budibase generates external tables, this denotes if a number field
|
// used specifically when Budibase generates external tables, this denotes if a number field
|
||||||
// is a foreign key used for a many-to-many relationship
|
// is a foreign key used for a many-to-many relationship
|
||||||
meta?: {
|
meta?: {
|
||||||
|
@ -40,18 +53,26 @@ export interface NumberFieldMetadata {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DateFieldMetadata {
|
export type NumberFieldMetadata = BaseFieldSchema & {
|
||||||
|
type: FieldType.NUMBER
|
||||||
|
autocolumn: boolean
|
||||||
|
} & (NumberForeignKeyMetadata | {})
|
||||||
|
|
||||||
|
export interface DateFieldMetadata extends BaseFieldSchema {
|
||||||
|
type: FieldType.DATETIME
|
||||||
ignoreTimezones?: boolean
|
ignoreTimezones?: boolean
|
||||||
timeOnly?: boolean
|
timeOnly?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StringFieldMetadata {
|
export interface StringFieldMetadata extends BaseFieldSchema {
|
||||||
|
type: FieldType.STRING
|
||||||
useRichText?: boolean | null
|
useRichText?: boolean | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FormulaFieldMetadata {
|
export interface FormulaFieldMetadata extends BaseFieldSchema {
|
||||||
|
type: FieldType.FORMULA
|
||||||
formula?: string
|
formula?: string
|
||||||
formulaType?: string
|
formulaType?: FormulaTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FieldConstraints {
|
export interface FieldConstraints {
|
||||||
|
@ -77,14 +98,7 @@ export interface FieldConstraints {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FieldSchema
|
interface BaseFieldSchema extends UIFieldMetadata {
|
||||||
extends UIFieldMetadata,
|
|
||||||
DateFieldMetadata,
|
|
||||||
RelationshipFieldMetadata,
|
|
||||||
AutoColumnFieldMetadata,
|
|
||||||
StringFieldMetadata,
|
|
||||||
FormulaFieldMetadata,
|
|
||||||
NumberFieldMetadata {
|
|
||||||
type: FieldType
|
type: FieldType
|
||||||
name: string
|
name: string
|
||||||
sortable?: boolean
|
sortable?: boolean
|
||||||
|
@ -93,6 +107,14 @@ export interface FieldSchema
|
||||||
constraints?: FieldConstraints
|
constraints?: FieldConstraints
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type FieldSchema =
|
||||||
|
| DateFieldMetadata
|
||||||
|
| RelationshipFieldMetadata
|
||||||
|
| AutoColumnFieldMetadata
|
||||||
|
| StringFieldMetadata
|
||||||
|
| FormulaFieldMetadata
|
||||||
|
| NumberFieldMetadata
|
||||||
|
|
||||||
export interface TableSchema {
|
export interface TableSchema {
|
||||||
[key: string]: FieldSchema
|
[key: string]: FieldSchema
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue