mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
/*
|
|
* cloudbeaver - Cloud Database Manager
|
|
* Copyright (C) 2020 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
|
|
import {
|
|
Connection, DBSource, ConnectionsManagerService
|
|
} from '@dbeaver/core/app';
|
|
import { injectable } from '@dbeaver/core/di';
|
|
import { PermissionsService, EPermission } from '@dbeaver/core/root';
|
|
import { ConnectionConfig, GraphQLService, CachedResource } from '@dbeaver/core/sdk';
|
|
|
|
@injectable()
|
|
export class BasicConnectionService {
|
|
readonly dbSources = new CachedResource([], this.loadDBSourcesAsync.bind(this), data => !!data.length)
|
|
|
|
constructor(
|
|
private graphQLService: GraphQLService,
|
|
private connectionsManagerService: ConnectionsManagerService,
|
|
private permissionsService: PermissionsService
|
|
) {
|
|
this.permissionsService.onUpdate.subscribe(() => this.dbSources.refresh());
|
|
}
|
|
|
|
public getDBSources(): DBSource[] {
|
|
return this.dbSources.data;
|
|
}
|
|
|
|
private async loadDBSourcesAsync(data: DBSource[]): Promise<DBSource[]> {
|
|
if (!await this.permissionsService.hasAsync(EPermission.public)) {
|
|
return [];
|
|
}
|
|
const { dataSourceList } = await this.graphQLService.gql.dataSourceList();
|
|
return dataSourceList;
|
|
}
|
|
|
|
async openConnectionAsync(config: ConnectionConfig): Promise<Connection> {
|
|
const response = await this.graphQLService.gql.openConnection({ config });
|
|
this.connectionsManagerService.addOpenedConnection(response.openConnection);
|
|
return response.openConnection;
|
|
}
|
|
}
|