Split back

This commit is contained in:
Adria Navarro 2024-01-05 16:39:55 +01:00
parent 1f9ee5a206
commit 498137ba7c
2 changed files with 13 additions and 7 deletions

View File

@ -33,7 +33,10 @@ export async function verify(
ctx: UserCtx<VerifyDatasourceRequest, VerifyDatasourceResponse>
) {
const { datasource } = ctx.request.body
const connector = await sdk.datasources.getConnector(datasource)
const enrichedDatasource = await sdk.datasources.getAndMergeDatasource(
datasource
)
const connector = await sdk.datasources.getConnector(enrichedDatasource)
if (!connector.testConnection) {
ctx.throw(400, "Connection information verification not supported")
}
@ -49,8 +52,11 @@ export async function information(
ctx: UserCtx<FetchDatasourceInfoRequest, FetchDatasourceInfoResponse>
) {
const { datasource } = ctx.request.body
const connector = (await sdk.datasources.getConnector(
const enrichedDatasource = await sdk.datasources.getAndMergeDatasource(
datasource
)
const connector = (await sdk.datasources.getConnector(
enrichedDatasource
)) as DatasourcePlus
if (!connector.getTableNames) {
ctx.throw(400, "Table name fetching not supported by datasource")
@ -328,7 +334,10 @@ export async function query(ctx: UserCtx) {
export async function getExternalSchema(ctx: UserCtx) {
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
const connector = await sdk.datasources.getConnector(datasource)
const enrichedDatasource = await sdk.datasources.getAndMergeDatasource(
datasource
)
const connector = await sdk.datasources.getConnector(enrichedDatasource)
if (!connector.getExternalSchema) {
ctx.throw(400, "Datasource does not support exporting external schema")

View File

@ -44,9 +44,6 @@ export async function getConnector(
datasource: Datasource
): Promise<IntegrationBase | DatasourcePlus> {
const Connector = await getIntegration(datasource.source)
datasource = await mergeAndEnrich(datasource)
// can't enrich if it doesn't have an ID yet
if (datasource._id) {
datasource = await datasources.enrich(datasource)
@ -55,7 +52,7 @@ export async function getConnector(
return new Connector(datasource.config)
}
async function mergeAndEnrich(datasource: Datasource) {
export async function getAndMergeDatasource(datasource: Datasource) {
if (datasource._id) {
const existingDatasource = await datasources.get(datasource._id)