2022-08-12 18:03:06 +02:00
|
|
|
import postgres from "./postgres"
|
|
|
|
import dynamodb from "./dynamodb"
|
|
|
|
import mongodb from "./mongodb"
|
|
|
|
import elasticsearch from "./elasticsearch"
|
|
|
|
import couchdb from "./couchdb"
|
|
|
|
import sqlServer from "./microsoftSqlServer"
|
|
|
|
import s3 from "./s3"
|
|
|
|
import airtable from "./airtable"
|
|
|
|
import mysql from "./mysql"
|
|
|
|
import arangodb from "./arangodb"
|
|
|
|
import rest from "./rest"
|
|
|
|
import googlesheets from "./googlesheets"
|
|
|
|
import firebase from "./firebase"
|
|
|
|
import redis from "./redis"
|
|
|
|
import snowflake from "./snowflake"
|
2022-09-30 11:52:00 +02:00
|
|
|
import oracle from "./oracle"
|
2022-08-12 18:03:06 +02:00
|
|
|
import { SourceName, Integration, PluginType } from "@budibase/types"
|
2022-08-17 11:05:13 +02:00
|
|
|
import { getDatasourcePlugin } from "../utilities/fileSystem"
|
2023-01-11 19:16:30 +01:00
|
|
|
import env from "../environment"
|
|
|
|
import { cloneDeep } from "lodash"
|
2023-04-11 17:37:26 +02:00
|
|
|
import sdk from "../sdk"
|
2020-11-26 15:43:56 +01:00
|
|
|
|
2023-05-12 12:19:05 +02:00
|
|
|
const DEFINITIONS: Record<SourceName, Integration | undefined> = {
|
2022-08-11 14:50:05 +02:00
|
|
|
[SourceName.POSTGRES]: postgres.schema,
|
|
|
|
[SourceName.DYNAMODB]: dynamodb.schema,
|
|
|
|
[SourceName.MONGODB]: mongodb.schema,
|
|
|
|
[SourceName.ELASTICSEARCH]: elasticsearch.schema,
|
|
|
|
[SourceName.COUCHDB]: couchdb.schema,
|
|
|
|
[SourceName.SQL_SERVER]: sqlServer.schema,
|
|
|
|
[SourceName.S3]: s3.schema,
|
|
|
|
[SourceName.AIRTABLE]: airtable.schema,
|
|
|
|
[SourceName.MYSQL]: mysql.schema,
|
|
|
|
[SourceName.ARANGODB]: arangodb.schema,
|
|
|
|
[SourceName.REST]: rest.schema,
|
|
|
|
[SourceName.FIRESTORE]: firebase.schema,
|
2022-10-10 10:02:17 +02:00
|
|
|
[SourceName.GOOGLE_SHEETS]: googlesheets.schema,
|
2022-08-11 14:50:05 +02:00
|
|
|
[SourceName.REDIS]: redis.schema,
|
|
|
|
[SourceName.SNOWFLAKE]: snowflake.schema,
|
2023-05-12 12:19:05 +02:00
|
|
|
[SourceName.ORACLE]: undefined,
|
2020-11-26 15:43:56 +01:00
|
|
|
}
|
|
|
|
|
2023-05-10 18:23:52 +02:00
|
|
|
const INTEGRATIONS: Record<SourceName, any> = {
|
2022-08-11 14:50:05 +02:00
|
|
|
[SourceName.POSTGRES]: postgres.integration,
|
|
|
|
[SourceName.DYNAMODB]: dynamodb.integration,
|
|
|
|
[SourceName.MONGODB]: mongodb.integration,
|
|
|
|
[SourceName.ELASTICSEARCH]: elasticsearch.integration,
|
|
|
|
[SourceName.COUCHDB]: couchdb.integration,
|
|
|
|
[SourceName.SQL_SERVER]: sqlServer.integration,
|
|
|
|
[SourceName.S3]: s3.integration,
|
|
|
|
[SourceName.AIRTABLE]: airtable.integration,
|
|
|
|
[SourceName.MYSQL]: mysql.integration,
|
|
|
|
[SourceName.ARANGODB]: arangodb.integration,
|
|
|
|
[SourceName.REST]: rest.integration,
|
|
|
|
[SourceName.FIRESTORE]: firebase.integration,
|
|
|
|
[SourceName.GOOGLE_SHEETS]: googlesheets.integration,
|
|
|
|
[SourceName.REDIS]: redis.integration,
|
|
|
|
[SourceName.SNOWFLAKE]: snowflake.integration,
|
2023-05-10 18:23:52 +02:00
|
|
|
[SourceName.ORACLE]: undefined,
|
2021-11-22 16:26:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// optionally add oracle integration if the oracle binary can be installed
|
2022-09-30 16:19:34 +02:00
|
|
|
if (
|
|
|
|
process.arch &&
|
|
|
|
!process.arch.startsWith("arm") &&
|
|
|
|
oracle.integration.isInstalled()
|
|
|
|
) {
|
2022-08-11 14:50:05 +02:00
|
|
|
DEFINITIONS[SourceName.ORACLE] = oracle.schema
|
|
|
|
INTEGRATIONS[SourceName.ORACLE] = oracle.integration
|
2020-11-26 15:43:56 +01:00
|
|
|
}
|
|
|
|
|
2023-05-12 12:19:05 +02:00
|
|
|
export async function getDefinition(
|
|
|
|
source: SourceName
|
|
|
|
): Promise<Integration | undefined> {
|
2023-02-10 13:47:23 +01:00
|
|
|
// check if its integrated, faster
|
2023-05-10 18:23:52 +02:00
|
|
|
const definition = DEFINITIONS[source]
|
|
|
|
if (definition) {
|
|
|
|
return definition
|
2023-02-10 13:47:23 +01:00
|
|
|
}
|
|
|
|
const allDefinitions = await getDefinitions()
|
|
|
|
return allDefinitions[source]
|
|
|
|
}
|
|
|
|
|
2022-11-22 20:49:59 +01:00
|
|
|
export async function getDefinitions() {
|
|
|
|
const pluginSchemas: { [key: string]: Integration } = {}
|
2023-01-11 19:16:30 +01:00
|
|
|
if (env.SELF_HOSTED) {
|
2023-04-11 17:37:26 +02:00
|
|
|
const plugins = await sdk.plugins.fetch(PluginType.DATASOURCE)
|
2022-11-22 20:49:59 +01:00
|
|
|
// extract the actual schema from each custom
|
|
|
|
for (let plugin of plugins) {
|
|
|
|
const sourceId = plugin.name
|
|
|
|
pluginSchemas[sourceId] = {
|
|
|
|
...plugin.schema["schema"],
|
|
|
|
custom: true,
|
|
|
|
}
|
|
|
|
if (plugin.iconUrl) {
|
|
|
|
pluginSchemas[sourceId].iconUrl = plugin.iconUrl
|
2022-08-15 19:38:09 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-22 20:49:59 +01:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
...cloneDeep(DEFINITIONS),
|
|
|
|
...pluginSchemas,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 18:23:52 +02:00
|
|
|
export async function getIntegration(integration: SourceName) {
|
2022-11-22 20:49:59 +01:00
|
|
|
if (INTEGRATIONS[integration]) {
|
|
|
|
return INTEGRATIONS[integration]
|
|
|
|
}
|
2023-01-11 19:16:30 +01:00
|
|
|
if (env.SELF_HOSTED) {
|
2023-04-11 17:37:26 +02:00
|
|
|
const plugins = await sdk.plugins.fetch(PluginType.DATASOURCE)
|
2022-11-22 20:49:59 +01:00
|
|
|
for (let plugin of plugins) {
|
|
|
|
if (plugin.name === integration) {
|
|
|
|
// need to use commonJS require due to its dynamic runtime nature
|
2023-05-12 12:19:05 +02:00
|
|
|
const retrieved = await getDatasourcePlugin(plugin)
|
2022-11-22 20:49:59 +01:00
|
|
|
if (retrieved.integration) {
|
|
|
|
return retrieved.integration
|
|
|
|
} else {
|
|
|
|
return retrieved
|
2022-09-02 20:32:15 +02:00
|
|
|
}
|
2022-08-17 11:05:13 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-22 20:49:59 +01:00
|
|
|
}
|
|
|
|
throw new Error("No datasource implementation found.")
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getDefinitions,
|
|
|
|
getIntegration,
|
2020-11-26 15:43:56 +01:00
|
|
|
}
|