Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cb 4661 remove includes concept from resources api #2910

Merged
merged 31 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f32a086
CB-4461 replaces includeMetaParameters concept for resource in Team f…
sergeyteleshev Sep 9, 2024
f101b9a
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 10, 2024
05093a5
CB-4461 removes includeMetaParameters for users resources
sergeyteleshev Sep 11, 2024
d4d60b9
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 12, 2024
e20583b
CB-4461 removes includeOriginDetails for users
sergeyteleshev Sep 13, 2024
ac10b68
CB-44661 renames to UsersMetaParametersResource
sergeyteleshev Sep 13, 2024
e9ff24c
CB-4461 removes includeOrigin and customIncludeOriginDetails includes…
sergeyteleshev Sep 13, 2024
1ff7028
CB-4461 removes the comment
sergeyteleshev Sep 13, 2024
5df3f4c
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 13, 2024
ee4b614
CB-4461 cleanup
sergeyteleshev Sep 16, 2024
3a24404
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 16, 2024
398a7f5
CB-4461 fixes pagination for new resources
sergeyteleshev Sep 16, 2024
865903d
CB-4661 pr fixes
sergeyteleshev Sep 16, 2024
23a1901
CB-4661 pr fixes 2
sergeyteleshev Sep 16, 2024
396429b
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 17, 2024
438ce9f
CB-4661 fixes origin info for connection templates table
sergeyteleshev Sep 17, 2024
ad22f29
CB-4661 fix pr
sergeyteleshev Sep 17, 2024
3f071f8
CB-4661 cleanup
sergeyteleshev Sep 17, 2024
ad8c5a2
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 18, 2024
84240cd
CB-4461 pr fixes
sergeyteleshev Sep 18, 2024
f077160
CB-4661 cleanup
sergeyteleshev Sep 18, 2024
82c0637
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 18, 2024
4493dc6
CB-4661 fix parallel loading of request for teams
sergeyteleshev Sep 18, 2024
9c850ca
CB-4661 cleanup
sergeyteleshev Sep 18, 2024
f2ff0ea
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
mr-anton-t Sep 19, 2024
d888fdc
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 20, 2024
4e57ce5
CB-4661 fixes aws/azure/gcp and other tabs in edit cloud connection
sergeyteleshev Sep 20, 2024
5f06d8e
Revert "CB-4661 fixes aws/azure/gcp and other tabs in edit cloud conn…
sergeyteleshev Sep 23, 2024
c3d52e4
CB-4661 adds correct fix for origin tab
sergeyteleshev Sep 23, 2024
35f0bdf
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
sergeyteleshev Sep 23, 2024
8a34a78
Merge branch 'devel' into CB-4661-remove-includes-concept-from-resour…
mr-anton-t Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export class TeamInfoMetaParametersResource extends CachedMapResource<string, Te
const { teams } = await this.graphQLService.sdk.getTeamsListMetaParameters({
teamId,
});

if (!teams.length) {
throw new Error(`Team ${teamId} not found`);
}

const metaParameters = teams[0].metaParameters;
Wroud marked this conversation as resolved.
Show resolved Hide resolved

if (teamId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class UsersMetaParametersResource extends CachedMapResource<string, UserM

protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, UserMetaParameter>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
const keys = resourceKeyList<string>([]);

if (all) {
throw new Error('Loading all users is prohibited');
Expand All @@ -61,8 +61,7 @@ export class UsersMetaParametersResource extends CachedMapResource<string, UserM
}
});

const key = resourceKeyList(keys);
this.set(key, userMetaParametersList);
this.set(keys, userMetaParametersList);

return this.data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class UsersOriginDetailsResource extends CachedMapResource<string, AdminO

protected async loader(originalKey: ResourceKey<string>): Promise<Map<string, AdminOriginDetailsFragment>> {
const all = this.aliases.isAlias(originalKey, CachedMapAllKey);
const keys: string[] = [];
const keys = resourceKeyList<string>([]);

if (all) {
throw new Error('Loading all users is prohibited');
Expand All @@ -50,8 +50,7 @@ export class UsersOriginDetailsResource extends CachedMapResource<string, AdminO
}
});

const key = resourceKeyList(keys);
this.set(key, userMetaParametersList);
this.set(keys, userMetaParametersList);

return this.data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import { DatabaseConnectionOriginDetailsFragment, GraphQLService } from '@cloudb
import { schemaValidationError } from '@cloudbeaver/core-utils';

import { CONNECTION_INFO_PARAM_SCHEMA, IConnectionInfoParams } from './CONNECTION_INFO_PARAM_SCHEMA';
import {
ConnectionInfoActiveProjectKey,
ConnectionInfoProjectKey,
ConnectionInfoResource,
createConnectionParam,
isConnectionInfoParamEqual,
} from './ConnectionInfoResource';
import { ConnectionInfoResource, createConnectionParam, isConnectionInfoParamEqual } from './ConnectionInfoResource';
import { parseConnectionKey } from './parseConnectionKey';

export type ConnectionInfoOriginDetails = DatabaseConnectionOriginDetailsFragment;

@injectable()
export class ConnectionInfoOriginDetailsResource extends CachedMapResource<IConnectionInfoParams, DatabaseConnectionOriginDetailsFragment> {
export class ConnectionInfoOriginDetailsResource extends CachedMapResource<IConnectionInfoParams, ConnectionInfoOriginDetails> {
constructor(
private readonly projectsService: ProjectsService,
private readonly graphQLService: GraphQLService,
Expand All @@ -39,35 +36,25 @@ export class ConnectionInfoOriginDetailsResource extends CachedMapResource<IConn
originalKey: ResourceKey<IConnectionInfoParams>,
_: any,
refresh?: boolean,
): Promise<Map<IConnectionInfoParams, DatabaseConnectionOriginDetailsFragment>> {
const connectionsList: DatabaseConnectionOriginDetailsFragment[] = [];
const projectKey = this.aliases.isAlias(originalKey, ConnectionInfoProjectKey);
): Promise<Map<IConnectionInfoParams, ConnectionInfoOriginDetails>> {
const connectionsList: ConnectionInfoOriginDetails[] = [];
let removedConnections: IConnectionInfoParams[] = [];
let projectId: string | undefined;
let projectIds: string[] | undefined;

if (projectKey) {
projectIds = projectKey.options.projectIds;
}

if (this.aliases.isAlias(originalKey, ConnectionInfoActiveProjectKey)) {
projectIds = this.projectsService.activeProjects.map(project => project.id);
}

if (isResourceAlias(originalKey)) {
const key = this.aliases.transformToKey(originalKey);
const outdated = ResourceKeyUtils.filter(key, key => this.isOutdated(key));
const parsed = parseConnectionKey({
originalKey,
aliases: this.aliases,
isOutdated: this.isOutdated.bind(this),
activeProjects: this.projectsService.activeProjects,
refresh,
});

if (!refresh && outdated.length === 1) {
originalKey = outdated[0]; // load only single connection
}
}
let { projectId } = parsed;
const { projectIds, key } = parsed;

await ResourceKeyUtils.forEachAsync(originalKey, async key => {
await ResourceKeyUtils.forEachAsync(key, async connectionKey => {
let connectionId: string | undefined;
if (!isResourceAlias(key)) {
projectId = key.projectId;
connectionId = key.connectionId;
if (!isResourceAlias(connectionKey)) {
projectId = connectionKey.projectId;
connectionId = connectionKey.connectionId;
}

const { connections } = await this.graphQLService.sdk.getUserConnectionsOriginDetails({
Expand All @@ -84,15 +71,15 @@ export class ConnectionInfoOriginDetailsResource extends CachedMapResource<IConn
});

runInAction(() => {
if (isResourceAlias(originalKey)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(originalKey)).filter(
key => !connectionsList.some(connection => isConnectionInfoParamEqual(key, createConnectionParam(connection))),
if (isResourceAlias(key)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(key)).filter(
filterKey => !connectionsList.some(connection => isConnectionInfoParamEqual(filterKey, createConnectionParam(connection))),
);
}

this.delete(resourceKeyList(removedConnections));
const key = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(key, connectionsList);
const keys = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(keys, connectionsList);
});

return this.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import {
createConnectionParam,
isConnectionInfoParamEqual,
} from './ConnectionInfoResource';
import { parseConnectionKey } from './parseConnectionKey';

export type ConnectionInfoOrigin = DatabaseConnectionOriginFragment;

@injectable()
export class ConnectionInfoOriginResource extends CachedMapResource<IConnectionInfoParams, DatabaseConnectionOriginFragment> {
export class ConnectionInfoOriginResource extends CachedMapResource<IConnectionInfoParams, ConnectionInfoOrigin> {
constructor(
private readonly projectsService: ProjectsService,
private readonly graphQLService: GraphQLService,
Expand All @@ -45,35 +48,25 @@ export class ConnectionInfoOriginResource extends CachedMapResource<IConnectionI
originalKey: ResourceKey<IConnectionInfoParams>,
_: any,
refresh?: boolean,
): Promise<Map<IConnectionInfoParams, DatabaseConnectionOriginFragment>> {
const connectionsList: DatabaseConnectionOriginFragment[] = [];
const projectKey = this.aliases.isAlias(originalKey, ConnectionInfoProjectKey);
): Promise<Map<IConnectionInfoParams, ConnectionInfoOrigin>> {
const connectionsList: ConnectionInfoOrigin[] = [];
let removedConnections: IConnectionInfoParams[] = [];
let projectId: string | undefined;
let projectIds: string[] | undefined;

if (projectKey) {
projectIds = projectKey.options.projectIds;
}

if (this.aliases.isAlias(originalKey, ConnectionInfoActiveProjectKey)) {
projectIds = this.projectsService.activeProjects.map(project => project.id);
}

if (isResourceAlias(originalKey)) {
const key = this.aliases.transformToKey(originalKey);
const outdated = ResourceKeyUtils.filter(key, key => this.isOutdated(key));
const parsed = parseConnectionKey({
originalKey,
aliases: this.aliases,
isOutdated: this.isOutdated.bind(this),
activeProjects: this.projectsService.activeProjects,
refresh,
});

if (!refresh && outdated.length === 1) {
originalKey = outdated[0]; // load only single connection
}
}
let { projectId } = parsed;
const { projectIds, key } = parsed;

await ResourceKeyUtils.forEachAsync(originalKey, async key => {
await ResourceKeyUtils.forEachAsync(key, async connectionKey => {
let connectionId: string | undefined;
if (!isResourceAlias(key)) {
projectId = key.projectId;
connectionId = key.connectionId;
if (!isResourceAlias(connectionKey)) {
projectId = connectionKey.projectId;
connectionId = connectionKey.connectionId;
}

const { connections } = await this.graphQLService.sdk.getUserConnectionsOrigin({
Expand All @@ -90,15 +83,15 @@ export class ConnectionInfoOriginResource extends CachedMapResource<IConnectionI
});

runInAction(() => {
if (isResourceAlias(originalKey)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(originalKey)).filter(
key => !connectionsList.some(connection => isConnectionInfoParamEqual(key, createConnectionParam(connection))),
if (isResourceAlias(key)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(key)).filter(
filterKey => !connectionsList.some(connection => isConnectionInfoParamEqual(filterKey, createConnectionParam(connection))),
);
}

this.delete(resourceKeyList(removedConnections));
const key = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(key, connectionsList);
const keys = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(keys, connectionsList);
});

return this.data;
Expand Down
48 changes: 20 additions & 28 deletions webapp/packages/core-connections/src/ConnectionInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { CONNECTION_INFO_PARAM_SCHEMA, type IConnectionInfoParams } from './CONN
import { ConnectionInfoEventHandler, IConnectionInfoEvent } from './ConnectionInfoEventHandler';
import type { DatabaseConnection } from './DatabaseConnection';
import { DBDriverResource } from './DBDriverResource';
import { parseConnectionKey } from './parseConnectionKey';

export type Connection = DatabaseConnection & {
authProperties?: UserConnectionAuthPropertiesFragment[];
Expand Down Expand Up @@ -490,41 +491,32 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
refresh: boolean,
): Promise<Map<IConnectionInfoParams, Connection>> {
const connectionsList: Connection[] = [];
const projectKey = this.aliases.isAlias(originalKey, ConnectionInfoProjectKey);
let removedConnections: IConnectionInfoParams[] = [];
let projectId: string | undefined;
let projectIds: string[] | undefined;

if (projectKey) {
projectIds = projectKey.options.projectIds;
}

if (this.aliases.isAlias(originalKey, ConnectionInfoActiveProjectKey)) {
projectIds = this.projectsService.activeProjects.map(project => project.id);
}

if (isResourceAlias(originalKey)) {
const key = this.aliases.transformToKey(originalKey);
const outdated = ResourceKeyUtils.filter(key, key => this.isOutdated(key, includes));
const parsed = parseConnectionKey({
originalKey,
aliases: this.aliases,
isOutdated: this.isOutdated.bind(this),
activeProjects: this.projectsService.activeProjects,
refresh,
});

if (!refresh && outdated.length === 1) {
originalKey = outdated[0]; // load only single connection
}
}
let { projectId } = parsed;
const { projectIds, key } = parsed;

await ResourceKeyUtils.forEachAsync(originalKey, async key => {
await ResourceKeyUtils.forEachAsync(key, async connectionKey => {
let connectionId: string | undefined;
if (!isResourceAlias(key)) {
projectId = key.projectId;
connectionId = key.connectionId;
if (!isResourceAlias(connectionKey)) {
projectId = connectionKey.projectId;
connectionId = connectionKey.connectionId;
}

const { connections } = await this.graphQLService.sdk.getUserConnections({
projectId,
connectionId,
projectIds,
...this.getDefaultIncludes(),
...this.getIncludesMap(key, includes),
...this.getIncludesMap(connectionKey, includes),
});

if (connectionId && !connections.some(connection => connection.id === connectionId)) {
Expand All @@ -535,15 +527,15 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
});

runInAction(() => {
if (isResourceAlias(originalKey)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(originalKey)).filter(
key => !connectionsList.some(connection => isConnectionInfoParamEqual(key, createConnectionParam(connection))),
if (isResourceAlias(key)) {
removedConnections = ResourceKeyUtils.toList(this.aliases.transformToKey(key)).filter(
filterKey => !connectionsList.some(connection => isConnectionInfoParamEqual(filterKey, createConnectionParam(connection))),
);
}

this.delete(resourceKeyList(removedConnections));
const key = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(key, connectionsList);
const keys = resourceKeyList(connectionsList.map(createConnectionParam));
this.set(keys, connectionsList);
});
this.sessionUpdate = false;

Expand Down
17 changes: 5 additions & 12 deletions webapp/packages/core-connections/src/DatabaseConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
* you may not use this file except in compliance with the License.
*/
import { AUTH_PROVIDER_LOCAL_ID } from '@cloudbeaver/core-authentication';
import type { DatabaseConnectionFragment, DatabaseConnectionOriginFragment } from '@cloudbeaver/core-sdk';
import type { DatabaseConnectionFragment, ObjectOriginInfoFragment } from '@cloudbeaver/core-sdk';

export type DatabaseConnection = DatabaseConnectionFragment;
export type DatabaseConnectionOrigin = DatabaseConnectionOriginFragment;

export function isLocalConnection(connectionOrigin: DatabaseConnectionOrigin | DatabaseConnection): boolean {
if (!('origin' in connectionOrigin) || !connectionOrigin.origin) {
return true;
}
return connectionOrigin.origin.type === AUTH_PROVIDER_LOCAL_ID;
export function isLocalConnection(origin: ObjectOriginInfoFragment): boolean {
return origin.type === AUTH_PROVIDER_LOCAL_ID;
}

export function isCloudConnection(connectionOrigin?: DatabaseConnectionOrigin): boolean {
if (!connectionOrigin?.origin) {
return false;
}
return connectionOrigin.origin.type === 'cloud';
export function isCloudConnection(origin: ObjectOriginInfoFragment): boolean {
return origin.type === 'cloud';
}
45 changes: 45 additions & 0 deletions webapp/packages/core-connections/src/parseConnectionKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 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 { isResourceAlias, ResourceAliases, ResourceKey, ResourceKeyUtils } from '@cloudbeaver/core-resource';
import { ProjectInfo } from '@cloudbeaver/core-sdk';

import { IConnectionInfoParams } from './CONNECTION_INFO_PARAM_SCHEMA';
import { ConnectionInfoActiveProjectKey, ConnectionInfoProjectKey } from './ConnectionInfoResource';

type Args = {
originalKey: ResourceKey<IConnectionInfoParams>;
aliases: ResourceAliases<IConnectionInfoParams>;
isOutdated: (key: ResourceKey<IConnectionInfoParams>) => boolean;
activeProjects: ProjectInfo[];
refresh?: boolean;
};

export function parseConnectionKey({ originalKey, aliases, isOutdated, activeProjects, refresh }: Args) {
const projectKey = aliases.isAlias(originalKey, ConnectionInfoProjectKey);
let projectId: string | undefined;
let projectIds: string[] | undefined;

if (projectKey) {
projectIds = projectKey.options.projectIds;
}

if (aliases.isAlias(originalKey, ConnectionInfoActiveProjectKey)) {
projectIds = activeProjects.map(project => project.id);
}

if (isResourceAlias(originalKey)) {
const key = aliases.transformToKey(originalKey);
const outdated = ResourceKeyUtils.filter(key, key => isOutdated(key));

if (!refresh && outdated.length === 1) {
originalKey = outdated[0]; // load only single connection
}
}

return { projectId, projectIds, key: originalKey };
}
1 change: 1 addition & 0 deletions webapp/packages/core-resource/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export * from './Resource/ICachedResourceMetadata';
export * from './Resource/IResource';
export * from './Resource/Resource';
export * from './Resource/ResourceAlias';
export * from './Resource/ResourceAliases';
export * from './Resource/ResourceError';
export * from './Resource/ResourceKey';
export * from './Resource/ResourceKeyAlias';
Expand Down
Loading
Loading