1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00
budibase/packages/builder/src/constants/backend/index.js

151 lines
3 KiB
JavaScript
Raw Normal View History

2020-06-16 03:41:31 +12:00
export const FIELDS = {
2020-08-08 03:13:57 +12:00
STRING: {
name: "Text",
2020-06-16 03:41:31 +12:00
icon: "ri-text",
2020-06-17 07:29:18 +12:00
type: "string",
constraints: {
2020-06-16 03:41:31 +12:00
type: "string",
2020-06-17 07:29:18 +12:00
length: {},
presence: false,
2020-06-16 03:41:31 +12:00
},
},
LONGFORM: {
name: "Long Form Text",
icon: "ri-file-text-line",
type: "longform",
constraints: {
type: "string",
length: {},
presence: false,
},
},
OPTIONS: {
name: "Options",
icon: "ri-list-check-2",
type: "options",
constraints: {
type: "string",
2020-10-12 08:42:30 +13:00
presence: false,
inclusion: [],
},
},
2020-06-16 03:41:31 +12:00
NUMBER: {
name: "Number",
icon: "ri-number-1",
2020-06-17 07:29:18 +12:00
type: "number",
constraints: {
2020-06-16 03:41:31 +12:00
type: "number",
presence: false,
numericality: { greaterThanOrEqualTo: "", lessThanOrEqualTo: "" },
2020-06-16 03:41:31 +12:00
},
},
BOOLEAN: {
name: "True/False",
icon: "ri-toggle-line",
2020-06-17 07:29:18 +12:00
type: "boolean",
constraints: {
2020-06-16 03:41:31 +12:00
type: "boolean",
presence: false,
2020-06-16 03:41:31 +12:00
},
},
DATETIME: {
name: "Date/Time",
icon: "ri-calendar-event-fill",
type: "datetime",
constraints: {
type: "string",
length: {},
presence: false,
datetime: {
latest: "",
earliest: "",
},
},
},
2020-09-12 02:09:56 +12:00
ATTACHMENT: {
name: "Attachment",
icon: "ri-file-line",
type: "attachment",
constraints: {
type: "array",
presence: false,
2020-09-12 02:09:56 +12:00
},
},
LINK: {
name: "Relationship",
icon: "ri-link",
type: "link",
constraints: {
type: "array",
2020-10-12 08:42:30 +13:00
presence: false,
},
},
}
export const AUTO_COLUMN_SUB_TYPES = {
CREATED_BY: "createdBy",
CREATED_AT: "createdAt",
UPDATED_BY: "updatedBy",
UPDATED_AT: "updatedAt",
AUTO_ID: "autoID",
2020-06-16 03:41:31 +12:00
}
2020-09-17 23:45:28 +12:00
export const FILE_TYPES = {
IMAGE: ["png", "tiff", "gif", "raw", "jpg", "jpeg"],
CODE: ["js", "rs", "py", "java", "rb", "hs", "yml"],
2020-09-18 03:36:39 +12:00
DOCUMENT: ["odf", "docx", "doc", "pdf", "csv"],
}
export const HostingTypes = {
CLOUD: "cloud",
SELF: "self",
}
2021-02-11 11:23:27 +13:00
export const Roles = {
ADMIN: "ADMIN",
POWER: "POWER",
BASIC: "BASIC",
PUBLIC: "PUBLIC",
BUILDER: "BUILDER",
}
export const USER_TABLE_ID = "ta_users"
export function isAutoColumnUserRelationship(subtype) {
return subtype === AUTO_COLUMN_SUB_TYPES.CREATED_BY ||
subtype === AUTO_COLUMN_SUB_TYPES.UPDATED_BY
}
export function buildAutoColumn(tableName, name, subtype) {
let type
switch (subtype) {
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY:
case AUTO_COLUMN_SUB_TYPES.CREATED_BY:
type = FIELDS.LINK.type
break
case AUTO_COLUMN_SUB_TYPES.AUTO_ID:
type = FIELDS.NUMBER.type
break
default:
type = FIELDS.STRING.type
break
}
if (Object.values(AUTO_COLUMN_SUB_TYPES).indexOf(subtype) === -1) {
throw "Cannot build auto column with supplied subtype"
}
const base = {
name,
type,
subtype,
icon: "ri-magic-line",
autocolumn: true,
// no constraints, this should never have valid inputs
constraints: {},
}
if (isAutoColumnUserRelationship(subtype)) {
base.tableId = USER_TABLE_ID
base.fieldName = `${tableName}-${name}`
}
return base
}