Skip to content

Commit 2a392bc

Browse files
committed
simplify
1 parent e6e6471 commit 2a392bc

File tree

6 files changed

+36
-59
lines changed

6 files changed

+36
-59
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/src/atlas-service.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import type { Logger } from '@mongodb-js/compass-logging';
1010
import type { PreferencesAccess } from 'compass-preferences-model';
1111
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
1212

13-
export enum UserDataType {
14-
FAVORITE_QUERIES = 'favoriteQueries',
15-
RECENT_QUERIES = 'recentQueries',
16-
FAVORITE_AGGREGATIONS = 'favoriteAggregations',
17-
}
18-
1913
export type AtlasServiceOptions = {
2014
defaultHeaders?: Record<string, string>;
2115
};
@@ -87,14 +81,17 @@ export class AtlasService {
8781
userDataEndpoint(
8882
orgId: string,
8983
groupId: string,
90-
type: UserDataType,
84+
type: 'favoriteQueries' | 'recentQueries' | 'favoriteAggregations',
9185
id?: string
9286
): string {
93-
[orgId, groupId, type, id] = [orgId, groupId, type, id || ''].map(encodeURIComponent);
87+
const encodedOrgId = encodeURIComponent(orgId);
88+
const encodedGroupId = encodeURIComponent(groupId);
89+
const encodedType = encodeURIComponent(type);
90+
const encodedId = id ? encodeURIComponent(id) : '';
9491
const baseUrl = this.config.userDataBaseUrl;
95-
const path = id
96-
? `/${orgId}/${groupId}/${type}/${id}`
97-
: `/${orgId}/${groupId}/${type}`;
92+
const path = encodedId
93+
? `/${encodedOrgId}/${encodedGroupId}/${encodedType}/${encodedId}`
94+
: `/${encodedOrgId}/${encodedGroupId}/${encodedType}`;
9895
return `${baseUrl}${path}`;
9996
}
10097
driverProxyEndpoint(path?: string): string {

packages/atlas-service/src/provider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ export const atlasServiceLocator = createServiceLocator(
6363

6464
export { AtlasAuthService } from './atlas-auth-service';
6565
export type { AtlasService } from './atlas-service';
66-
export { UserDataType } from './atlas-service';
6766
export type { AtlasUserInfo } from './renderer';

packages/compass-web/src/entrypoint.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ import {
5050
atlasServiceLocator,
5151
AtlasServiceProvider,
5252
} from '@mongodb-js/atlas-service/provider';
53-
// Define UserDataType enum locally to avoid dependency issues
54-
enum UserDataType {
55-
FAVORITE_QUERIES = 'favoriteQueries',
56-
RECENT_QUERIES = 'recentQueries',
57-
FAVORITE_AGGREGATIONS = 'favoriteAggregations',
58-
}
5953
import { AtlasAiServiceProvider } from '@mongodb-js/compass-generative-ai/provider';
6054
import { LoggerProvider } from '@mongodb-js/compass-logging/provider';
6155
import { TelemetryProvider } from '@mongodb-js/compass-telemetry/provider';
@@ -125,7 +119,10 @@ const WithStorageProviders = createServiceProvider(
125119
atlasService.authenticatedFetch.bind(atlasService);
126120
const getResourceUrl = (path?: string) => {
127121
const pathParts = path?.split('/').filter(Boolean) || [];
128-
const type = pathParts[0] as UserDataType;
122+
const type = pathParts[0] as
123+
| 'favoriteQueries'
124+
| 'recentQueries'
125+
| 'favoriteAggregations';
129126
const pathOrgId = pathParts[1];
130127
const pathProjectId = pathParts[2];
131128
const id = pathParts[3];

packages/my-queries-storage/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
"typescript": "^5.9.2"
7676
},
7777
"dependencies": {
78-
"@mongodb-js/atlas-service": "^0.62.0",
7978
"@mongodb-js/compass-app-registry": "^9.4.25",
8079
"@mongodb-js/compass-editor": "^0.56.0",
8180
"@mongodb-js/compass-user-data": "^0.10.1",

packages/my-queries-storage/src/storage-factories.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EJSON } from 'bson';
22
import { AtlasUserData, FileUserData } from '@mongodb-js/compass-user-data';
3-
import { UserDataType } from '@mongodb-js/atlas-service/provider';
43
import { RecentQuerySchema, FavoriteQuerySchema } from './query-storage-schema';
54
import { PipelineSchema } from './pipeline-storage-schema';
65
import {
@@ -21,50 +20,38 @@ export type WebStorageOptions = {
2120
};
2221

2322
export function createWebRecentQueryStorage(options: WebStorageOptions) {
24-
const userData = new AtlasUserData(
25-
RecentQuerySchema,
26-
UserDataType.RECENT_QUERIES,
27-
{
28-
orgId: options.orgId,
29-
projectId: options.projectId,
30-
getResourceUrl: options.getResourceUrl,
31-
authenticatedFetch: options.authenticatedFetch,
32-
serialize: (content) => EJSON.stringify(content),
33-
deserialize: (content: string) => EJSON.parse(content),
34-
}
35-
);
23+
const userData = new AtlasUserData(RecentQuerySchema, 'recentQueries', {
24+
orgId: options.orgId,
25+
projectId: options.projectId,
26+
getResourceUrl: options.getResourceUrl,
27+
authenticatedFetch: options.authenticatedFetch,
28+
serialize: (content) => EJSON.stringify(content),
29+
deserialize: (content: string) => EJSON.parse(content),
30+
});
3631
return new BaseCompassRecentQueryStorage(userData);
3732
}
3833

3934
export function createWebFavoriteQueryStorage(options: WebStorageOptions) {
40-
const userData = new AtlasUserData(
41-
FavoriteQuerySchema,
42-
UserDataType.FAVORITE_QUERIES,
43-
{
44-
orgId: options.orgId,
45-
projectId: options.projectId,
46-
getResourceUrl: options.getResourceUrl,
47-
authenticatedFetch: options.authenticatedFetch,
48-
serialize: (content) => EJSON.stringify(content),
49-
deserialize: (content: string) => EJSON.parse(content),
50-
}
51-
);
35+
const userData = new AtlasUserData(FavoriteQuerySchema, 'favoriteQueries', {
36+
orgId: options.orgId,
37+
projectId: options.projectId,
38+
getResourceUrl: options.getResourceUrl,
39+
authenticatedFetch: options.authenticatedFetch,
40+
serialize: (content) => EJSON.stringify(content),
41+
deserialize: (content: string) => EJSON.parse(content),
42+
});
5243
return new BaseCompassFavoriteQueryStorage(userData);
5344
}
5445

5546
export function createWebPipelineStorage(options: WebStorageOptions) {
56-
const userData = new AtlasUserData(
57-
PipelineSchema,
58-
UserDataType.FAVORITE_AGGREGATIONS,
59-
{
60-
orgId: options.orgId,
61-
projectId: options.projectId,
62-
getResourceUrl: options.getResourceUrl,
63-
authenticatedFetch: options.authenticatedFetch,
64-
serialize: (content) => EJSON.stringify(content),
65-
deserialize: (content: string) => EJSON.parse(content),
66-
}
67-
);
47+
const userData = new AtlasUserData(PipelineSchema, 'favoriteAggregations', {
48+
orgId: options.orgId,
49+
projectId: options.projectId,
50+
getResourceUrl: options.getResourceUrl,
51+
authenticatedFetch: options.authenticatedFetch,
52+
serialize: (content) => EJSON.stringify(content),
53+
deserialize: (content: string) => EJSON.parse(content),
54+
});
6855
return new BaseCompassPipelineStorage<typeof PipelineSchema>(userData);
6956
}
7057

0 commit comments

Comments
 (0)