diff --git a/packages/backend-core/src/db/constants.js b/packages/backend-core/src/db/constants.js deleted file mode 100644 index 8bdf0f56de..0000000000 --- a/packages/backend-core/src/db/constants.js +++ /dev/null @@ -1,61 +0,0 @@ -exports.SEPARATOR = "_" -exports.UNICODE_MAX = "\ufff0" - -const PRE_APP = "app" -const PRE_DEV = "dev" - -/** - * Can be used to create a few different forms of querying a view. - */ -exports.ViewModes = { - ALL: "all", - AUTOMATION: "auto", - STATUS: "status", -} - -exports.ViewNames = { - USER_BY_EMAIL: "by_email", - BY_API_KEY: "by_api_key", - USER_BY_BUILDERS: "by_builders", - LINK: "by_link", - ROUTING: "screen_routes", - AUTO_LOGS: "auto_log", -} - -exports.DocumentTypes = { - USER: "us", - WORKSPACE: "workspace", - CONFIG: "config", - TEMPLATE: "template", - APP: PRE_APP, - DEV: PRE_DEV, - APP_DEV: `${PRE_APP}${exports.SEPARATOR}${PRE_DEV}`, - APP_METADATA: `${PRE_APP}${exports.SEPARATOR}metadata`, - ROLE: "role", - MIGRATIONS: "migrations", - DEV_INFO: "devinfo", - AUTOMATION_LOG: "log_au", -} - -exports.StaticDatabases = { - GLOBAL: { - name: "global-db", - docs: { - apiKeys: "apikeys", - usageQuota: "usage_quota", - licenseInfo: "license_info", - }, - }, - // contains information about tenancy and so on - PLATFORM_INFO: { - name: "global-info", - docs: { - tenants: "tenants", - install: "install", - }, - }, -} - -exports.APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR -exports.APP_DEV = exports.APP_DEV_PREFIX = - exports.DocumentTypes.APP_DEV + exports.SEPARATOR diff --git a/packages/backend-core/src/db/constants.ts b/packages/backend-core/src/db/constants.ts new file mode 100644 index 0000000000..be0e824e61 --- /dev/null +++ b/packages/backend-core/src/db/constants.ts @@ -0,0 +1,58 @@ +export const SEPARATOR = "_" +export const UNICODE_MAX = "\ufff0" + +/** + * Can be used to create a few different forms of querying a view. + */ +export enum AutomationViewModes { + ALL = "all", + AUTOMATION = "automation", + STATUS = "status", +} + +export enum ViewNames { + USER_BY_EMAIL = "by_email", + BY_API_KEY = "by_api_key", + USER_BY_BUILDERS = "by_builders", + LINK = "by_link", + ROUTING = "screen_routes", + AUTOMATION_LOGS = "automation_logs", +} + +export enum DocumentTypes { + USER = "us", + WORKSPACE = "workspace", + CONFIG = "config", + TEMPLATE = "template", + APP = "app", + DEV = "dev", + APP_DEV = "app_dev", + APP_METADATA = "app_metadata", + ROLE = "role", + MIGRATIONS = "migrations", + DEV_INFO = "devinfo", + AUTOMATION_LOG = "log_au", +} + +export const StaticDatabases = { + GLOBAL: { + name: "global-db", + docs: { + apiKeys: "apikeys", + usageQuota: "usage_quota", + licenseInfo: "license_info", + }, + }, + // contains information about tenancy and so on + PLATFORM_INFO: { + name: "global-info", + docs: { + tenants: "tenants", + install: "install", + }, + }, +} + +export const APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR +export const APP_DEV = exports.DocumentTypes.APP_DEV + exports.SEPARATOR +export const APP_DEV_PREFIX = APP_DEV diff --git a/packages/backend-core/src/db/utils.ts b/packages/backend-core/src/db/utils.ts index adaf33af98..4910899565 100644 --- a/packages/backend-core/src/db/utils.ts +++ b/packages/backend-core/src/db/utils.ts @@ -1,7 +1,7 @@ import { newid } from "../hashing" import { DEFAULT_TENANT_ID, Configs } from "../constants" import env from "../environment" -import { SEPARATOR, DocumentTypes, UNICODE_MAX } from "./constants" +import { SEPARATOR, DocumentTypes, UNICODE_MAX, ViewNames } from "./constants" import { getTenantId, getGlobalDBName, getGlobalDB } from "../tenancy" import fetch from "node-fetch" import { doWithDB, allDbs } from "./index" @@ -58,7 +58,7 @@ export function getDocParams( /** * Retrieve the correct index for a view based on default design DB. */ -export function getQueryIndex(viewName: string) { +export function getQueryIndex(viewName: ViewNames) { return `database/${viewName}` } diff --git a/packages/builder/src/components/portal/overview/HistoryDetailsPanel.svelte b/packages/builder/src/components/portal/overview/automation/HistoryDetailsPanel.svelte similarity index 100% rename from packages/builder/src/components/portal/overview/HistoryDetailsPanel.svelte rename to packages/builder/src/components/portal/overview/automation/HistoryDetailsPanel.svelte diff --git a/packages/builder/src/components/portal/overview/HistoryTab.svelte b/packages/builder/src/components/portal/overview/automation/HistoryTab.svelte similarity index 100% rename from packages/builder/src/components/portal/overview/HistoryTab.svelte rename to packages/builder/src/components/portal/overview/automation/HistoryTab.svelte diff --git a/packages/builder/src/components/portal/overview/StatusRenderer.svelte b/packages/builder/src/components/portal/overview/automation/StatusRenderer.svelte similarity index 100% rename from packages/builder/src/components/portal/overview/StatusRenderer.svelte rename to packages/builder/src/components/portal/overview/automation/StatusRenderer.svelte diff --git a/packages/server/src/automations/logging/index.ts b/packages/server/src/automations/logging/index.ts index 2467350a4d..cbb56a1abc 100644 --- a/packages/server/src/automations/logging/index.ts +++ b/packages/server/src/automations/logging/index.ts @@ -5,15 +5,13 @@ import { isProdAppID, SEPARATOR, } from "../../db/utils" -import { Automation, MetadataErrors } from "../../definitions/common" +import { Automation } from "../../definitions/common" import { app } from "@budibase/backend-core/cache" import { backOff } from "../../utilities" import * as env from "../../environment" import { logs } from "@budibase/pro" -import { - AutomationResults, - AutomationStatus, -} from "../../definitions/automation" +import { AppMetadataErrors } from "@budibase/types" +import { AutomationResults, AutomationStatus } from "@budibase/types" const { logAlert } = require("@budibase/backend-core/logging") @@ -75,9 +73,9 @@ async function updateAppMetadataWithErrors( const autoId = `${parts[parts.length - 3]}${SEPARATOR}${ parts[parts.length - 2] }` - let errors: MetadataErrors = {} + let errors: AppMetadataErrors = {} if (metadata.automationErrors) { - errors = metadata.automationErrors as MetadataErrors + errors = metadata.automationErrors as AppMetadataErrors } if (!Array.isArray(errors[autoId])) { errors[autoId] = [] diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 154f765315..99831e4ca3 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -43,12 +43,6 @@ const DocumentTypes = { USER_FLAG: "flag", } -const ViewModes = { - ALL: "all", - AUTOMATION: "auto", - STATUS: "status", -} - const InternalTables = { USER_METADATA: "ta_users", } @@ -75,7 +69,6 @@ exports.USER_METDATA_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${InternalTables. exports.LINK_USER_METADATA_PREFIX = `${DocumentTypes.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}` exports.TABLE_ROW_PREFIX = `${DocumentTypes.ROW}${SEPARATOR}${DocumentTypes.TABLE}` exports.ViewNames = ViewNames -exports.ViewModes = ViewModes exports.InternalTables = InternalTables exports.DocumentTypes = DocumentTypes exports.SEPARATOR = SEPARATOR @@ -365,32 +358,6 @@ exports.generateAutomationLogID = (isoDate, status, automationId) => { return `${DocumentTypes.AUTOMATION_LOG}${SEPARATOR}${isoDate}${SEPARATOR}${automationId}${SEPARATOR}${status}` } -exports.getAutomationLogParams = ( - startDate, - endDate, - { status, automationId } = {}, - otherProps = {} -) => { - const automationBase = automationId ? `${automationId}${SEPARATOR}` : "" - const statusBase = status ? `${status}${SEPARATOR}` : "" - let base - if (status && automationId) { - base = `${ViewModes.ALL}${SEPARATOR}${statusBase}${automationBase}` - } else if (status) { - base = `${ViewModes.STATUS}${SEPARATOR}${statusBase}` - } else if (automationId) { - base = `${ViewModes.AUTOMATION}${SEPARATOR}${automationBase}` - } else { - base = `${DocumentTypes.AUTOMATION_LOG}${SEPARATOR}` - } - return { - ...otherProps, - descending: true, - startkey: `${base}${endDate}${UNICODE_MAX}`, - endkey: `${base}${startDate}`, - } -} - /** * This can be used with the db.allDocs to get a list of IDs */ diff --git a/packages/server/src/definitions/automation.ts b/packages/server/src/definitions/automation.ts deleted file mode 100644 index 8ed339d0a0..0000000000 --- a/packages/server/src/definitions/automation.ts +++ /dev/null @@ -1,32 +0,0 @@ -export enum AutomationStatus { - SUCCESS = "success", - ERROR = "error", - STOPPED = "stopped", -} - -export interface AutomationResults { - automationId: string - status: string - trigger?: any - steps: { - stepId: string - inputs: { - [key: string]: any - } - outputs: { - [key: string]: any - } - }[] -} - -export interface AutomationLog extends AutomationResults { - createdAt: string - _id: string - _rev: string -} - -export interface AutomationLogPage { - data: AutomationLog[] - hasNextPage: boolean - nextPage?: string -} diff --git a/packages/server/src/definitions/common.ts b/packages/server/src/definitions/common.ts index 9da65b6453..f7e5a9a049 100644 --- a/packages/server/src/definitions/common.ts +++ b/packages/server/src/definitions/common.ts @@ -1,5 +1,3 @@ -import { AutomationStatus } from "./automation" - export { Query, Datasource } from "./datasource" export interface Base { @@ -105,5 +103,3 @@ export interface Automation extends Base { trigger?: AutomationStep } } - -export type MetadataErrors = { [key: string]: string[] } diff --git a/packages/types/src/documents/app/app.ts b/packages/types/src/documents/app/app.ts index fbad9190f5..1e9bffb867 100644 --- a/packages/types/src/documents/app/app.ts +++ b/packages/types/src/documents/app/app.ts @@ -1,5 +1,7 @@ import { Document } from "../document" +export type AppMetadataErrors = { [key: string]: string[] } + export interface App extends Document { appId: string type: string @@ -12,6 +14,7 @@ export interface App extends Document { tenantId: string status: string revertableVersion?: string + automationErrors?: AppMetadataErrors } export interface AppInstance { diff --git a/packages/types/src/documents/app/automation.ts b/packages/types/src/documents/app/automation.ts index ae6c3918a6..9b8b573b66 100644 --- a/packages/types/src/documents/app/automation.ts +++ b/packages/types/src/documents/app/automation.ts @@ -17,3 +17,34 @@ export interface AutomationTrigger { id: string stepId: string } + +export enum AutomationStatus { + SUCCESS = "success", + ERROR = "error", + STOPPED = "stopped", +} + +export interface AutomationResults { + automationId: string + status: string + trigger?: any + steps: { + stepId: string + inputs: { + [key: string]: any + } + outputs: { + [key: string]: any + } + }[] +} + +export interface AutomationLog extends AutomationResults, Document { + _rev: string +} + +export interface AutomationLogPage { + data: AutomationLog[] + hasNextPage: boolean + nextPage?: string +}