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 { 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 {
|
||||
STRING = "string",
|
||||
|
@ -39,11 +44,6 @@ export const SwitchableTypes = CanSwitchTypes.reduce((prev, current) =>
|
|||
prev ? prev.concat(current) : current
|
||||
)
|
||||
|
||||
export enum FormulaTypes {
|
||||
STATIC = "static",
|
||||
DYNAMIC = "dynamic",
|
||||
}
|
||||
|
||||
export enum AuthTypes {
|
||||
APP = "app",
|
||||
BUILDER = "builder",
|
||||
|
@ -132,14 +132,6 @@ export const USERS_TABLE_SCHEMA = {
|
|||
primaryDisplay: "email",
|
||||
}
|
||||
|
||||
export enum AutoFieldSubTypes {
|
||||
CREATED_BY = "createdBy",
|
||||
CREATED_AT = "createdAt",
|
||||
UPDATED_BY = "updatedBy",
|
||||
UPDATED_AT = "updatedAt",
|
||||
AUTO_ID = "autoID",
|
||||
}
|
||||
|
||||
export enum AutoFieldDefaultNames {
|
||||
CREATED_BY = "Created By",
|
||||
CREATED_AT = "Created At",
|
||||
|
|
|
@ -7,3 +7,16 @@ export enum RelationshipType {
|
|||
export enum AutoReason {
|
||||
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
|
||||
// column size, position and whether it can be viewed
|
||||
import { FieldType } from "../row"
|
||||
import { AutoReason, RelationshipType } from "./constants"
|
||||
import {
|
||||
AutoFieldSubTypes,
|
||||
AutoReason,
|
||||
FormulaTypes,
|
||||
RelationshipType,
|
||||
} from "./constants"
|
||||
|
||||
export interface UIFieldMetadata {
|
||||
order?: number
|
||||
|
@ -10,20 +15,25 @@ export interface UIFieldMetadata {
|
|||
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
|
||||
fieldName?: string
|
||||
tableId?: string
|
||||
// below is used for SQL relationships, needed to define the foreign keys
|
||||
// or the tables used for many-to-many relationships (through)
|
||||
relationshipType?: RelationshipType
|
||||
through?: string
|
||||
foreignKey?: string
|
||||
throughFrom?: string
|
||||
throughTo?: string
|
||||
}
|
||||
tableId: string
|
||||
} & (ManyToManyRelationshipFieldMetadata | OneSidedRelationshipFieldMetadata)
|
||||
|
||||
export interface AutoColumnFieldMetadata {
|
||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.AUTO
|
||||
autocolumn?: boolean
|
||||
subtype?: string
|
||||
lastID?: number
|
||||
|
@ -31,7 +41,10 @@ export interface AutoColumnFieldMetadata {
|
|||
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
|
||||
// is a foreign key used for a many-to-many relationship
|
||||
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
|
||||
timeOnly?: boolean
|
||||
}
|
||||
|
||||
export interface StringFieldMetadata {
|
||||
export interface StringFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.STRING
|
||||
useRichText?: boolean | null
|
||||
}
|
||||
|
||||
export interface FormulaFieldMetadata {
|
||||
export interface FormulaFieldMetadata extends BaseFieldSchema {
|
||||
type: FieldType.FORMULA
|
||||
formula?: string
|
||||
formulaType?: string
|
||||
formulaType?: FormulaTypes
|
||||
}
|
||||
|
||||
export interface FieldConstraints {
|
||||
|
@ -77,14 +98,7 @@ export interface FieldConstraints {
|
|||
}
|
||||
}
|
||||
|
||||
export interface FieldSchema
|
||||
extends UIFieldMetadata,
|
||||
DateFieldMetadata,
|
||||
RelationshipFieldMetadata,
|
||||
AutoColumnFieldMetadata,
|
||||
StringFieldMetadata,
|
||||
FormulaFieldMetadata,
|
||||
NumberFieldMetadata {
|
||||
interface BaseFieldSchema extends UIFieldMetadata {
|
||||
type: FieldType
|
||||
name: string
|
||||
sortable?: boolean
|
||||
|
@ -93,6 +107,14 @@ export interface FieldSchema
|
|||
constraints?: FieldConstraints
|
||||
}
|
||||
|
||||
export type FieldSchema =
|
||||
| DateFieldMetadata
|
||||
| RelationshipFieldMetadata
|
||||
| AutoColumnFieldMetadata
|
||||
| StringFieldMetadata
|
||||
| FormulaFieldMetadata
|
||||
| NumberFieldMetadata
|
||||
|
||||
export interface TableSchema {
|
||||
[key: string]: FieldSchema
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue