1
0
Fork 0
mirror of synced 2024-07-13 18:26:06 +12:00

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

View file

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