2022-08-12 03:36:07 +12:00
|
|
|
const { DocumentType, getPluginParams } = require("../../db/utils")
|
2021-03-26 02:32:05 +13:00
|
|
|
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
|
2022-01-28 07:18:31 +13:00
|
|
|
const { getAppDB } = require("@budibase/backend-core/context")
|
2022-08-12 02:30:59 +12:00
|
|
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
2022-09-03 06:32:15 +12:00
|
|
|
const env = require("../../environment")
|
2020-05-03 02:29:10 +12:00
|
|
|
|
2021-05-03 19:31:09 +12:00
|
|
|
exports.fetchAppComponentDefinitions = async function (ctx) {
|
2022-08-25 21:57:30 +12:00
|
|
|
try {
|
|
|
|
const db = getAppDB()
|
|
|
|
const app = await db.get(DocumentType.APP_METADATA)
|
2020-10-29 09:35:06 +13:00
|
|
|
|
2022-08-25 21:57:30 +12:00
|
|
|
let componentManifests = await Promise.all(
|
|
|
|
app.componentLibraries.map(async library => {
|
|
|
|
let manifest = await getComponentLibraryManifest(library)
|
|
|
|
return {
|
|
|
|
manifest,
|
|
|
|
library,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const definitions = {}
|
|
|
|
for (let { manifest, library } of componentManifests) {
|
|
|
|
for (let key of Object.keys(manifest)) {
|
|
|
|
if (key === "features") {
|
|
|
|
definitions[key] = manifest[key]
|
|
|
|
} else {
|
|
|
|
const fullComponentName = `${library}/${key}`.toLowerCase()
|
|
|
|
definitions[fullComponentName] = {
|
|
|
|
component: fullComponentName,
|
|
|
|
...manifest[key],
|
|
|
|
}
|
2021-07-08 00:53:59 +12:00
|
|
|
}
|
2020-05-07 21:53:34 +12:00
|
|
|
}
|
2020-10-29 09:35:06 +13:00
|
|
|
}
|
2022-08-12 02:30:59 +12:00
|
|
|
|
2022-09-03 06:32:15 +12:00
|
|
|
// for now custom components only supported in self-host
|
|
|
|
if (env.SELF_HOSTED) {
|
|
|
|
// Add custom components
|
|
|
|
const globalDB = getGlobalDB()
|
|
|
|
const response = await globalDB.allDocs(
|
|
|
|
getPluginParams(null, {
|
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
response.rows
|
|
|
|
.map(row => row.doc)
|
|
|
|
.filter(plugin => plugin.schema.type === "component")
|
|
|
|
.forEach(plugin => {
|
2022-09-03 06:52:52 +12:00
|
|
|
const fullComponentName = `plugin/${plugin.name}`
|
2022-09-03 06:32:15 +12:00
|
|
|
definitions[fullComponentName] = {
|
|
|
|
component: fullComponentName,
|
|
|
|
...plugin.schema.schema,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-08-12 02:30:59 +12:00
|
|
|
|
2022-08-25 21:57:30 +12:00
|
|
|
ctx.body = definitions
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`component-definitions=failed`, err)
|
2021-03-24 06:54:02 +13:00
|
|
|
}
|
2020-05-07 21:53:34 +12:00
|
|
|
}
|