Main body of PR comments - still need to move a bit to pro.

This commit is contained in:
mike12345567 2022-07-04 11:12:08 +01:00
parent c0d8995053
commit 11f1e95cc0
12 changed files with 99 additions and 139 deletions

View File

@ -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

View File

@ -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

View File

@ -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}`
}

View File

@ -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] = []

View File

@ -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
*/

View File

@ -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
}

View File

@ -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[] }

View File

@ -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 {

View File

@ -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
}