export const FIELDS = { STRING: { name: "Text", icon: "ri-text", type: "string", constraints: { type: "string", length: {}, presence: false, }, }, 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", presence: false, inclusion: [], }, }, NUMBER: { name: "Number", icon: "ri-number-1", type: "number", constraints: { type: "number", presence: false, numericality: { greaterThanOrEqualTo: "", lessThanOrEqualTo: "" }, }, }, BOOLEAN: { name: "True/False", icon: "ri-toggle-line", type: "boolean", constraints: { type: "boolean", presence: false, }, }, DATETIME: { name: "Date/Time", icon: "ri-calendar-event-fill", type: "datetime", constraints: { type: "string", length: {}, presence: false, datetime: { latest: "", earliest: "", }, }, }, ATTACHMENT: { name: "Attachment", icon: "ri-file-line", type: "attachment", constraints: { type: "array", presence: false, }, }, LINK: { name: "Relationship", icon: "ri-link", type: "link", constraints: { type: "array", presence: false, }, } } export const AUTO_COLUMN_SUB_TYPES = { AUTO_ID: "autoID", CREATED_BY: "createdBy", CREATED_AT: "createdAt", UPDATED_BY: "updatedBy", UPDATED_AT: "updatedAt", } export const AUTO_COLUMN_DISPLAY_NAMES = { AUTO_ID: "Auto ID", CREATED_BY: "Created By", CREATED_AT: "Created At", UPDATED_BY: "Updated By", UPDATED_AT: "Updated At", } export const FILE_TYPES = { IMAGE: ["png", "tiff", "gif", "raw", "jpg", "jpeg"], CODE: ["js", "rs", "py", "java", "rb", "hs", "yml"], DOCUMENT: ["odf", "docx", "doc", "pdf", "csv"], } export const HostingTypes = { CLOUD: "cloud", SELF: "self", } 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 getAutoColumnInformation(enabled = true) { let info = {} for (let [key, subtype] of Object.entries(AUTO_COLUMN_SUB_TYPES)) { info[subtype] = {enabled, name: AUTO_COLUMN_DISPLAY_NAMES[key]} } return info } export function buildAutoColumn(tableName, name, subtype) { let type, constraints switch (subtype) { case AUTO_COLUMN_SUB_TYPES.UPDATED_BY: case AUTO_COLUMN_SUB_TYPES.CREATED_BY: type = FIELDS.LINK.type constraints = FIELDS.LINK.constraints break case AUTO_COLUMN_SUB_TYPES.AUTO_ID: type = FIELDS.NUMBER.type constraints = FIELDS.NUMBER.constraints break default: type = FIELDS.STRING.type constraints = FIELDS.STRING.constraints 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, constraints, } if (isAutoColumnUserRelationship(subtype)) { base.tableId = USER_TABLE_ID base.fieldName = `${tableName}-${name}` } return base }