Skip to content

Commit 61265d6

Browse files
committed
working demo
1 parent 3eab096 commit 61265d6

File tree

9 files changed

+31
-28
lines changed

9 files changed

+31
-28
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export class AtlasService {
7676
return this.cloudEndpoint(path);
7777
}
7878
tempEndpoint(path?: string): string {
79-
return `${normalizePath(path)}`;
79+
return `https://cluster-connection.cloud-dev.mongodb.com${normalizePath(
80+
path
81+
)}`;
8082
}
8183
driverProxyEndpoint(path?: string): string {
8284
return `${this.config.ccsBaseUrl}${normalizePath(path)}`;
@@ -91,13 +93,14 @@ export class AtlasService {
9193
{ url }
9294
);
9395
try {
96+
const headers = {
97+
...this.options?.defaultHeaders,
98+
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
99+
...init?.headers,
100+
};
94101
const res = await fetch(url, {
95102
...init,
96-
headers: {
97-
...this.options?.defaultHeaders,
98-
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
99-
...init?.headers,
100-
},
103+
headers,
101104
});
102105
this.logger.log.info(
103106
this.logger.mongoLogId(1_001_000_309),
@@ -125,7 +128,6 @@ export class AtlasService {
125128
url: RequestInfo | URL,
126129
init?: RequestInit
127130
): Promise<Response> {
128-
debugger;
129131
const authHeaders = await this.authService.getAuthHeaders();
130132
return this.fetch(url, {
131133
...init,

packages/compass-aggregations/src/modules/saved-pipeline.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ export const savedPipelineAdd = (
7777

7878
export const getSavedPipelines =
7979
(): PipelineBuilderThunkAction<void> => (dispatch, getState) => {
80-
console.log('Get saved pipelines');
81-
// debugger;
8280
if (!getState().savedPipeline.isLoaded) {
8381
dispatch(updatePipelineList());
8482
}
@@ -95,8 +93,6 @@ export const updatePipelineList =
9593
{ pipelineStorage, logger: { debug }, globalAppRegistry }
9694
) => {
9795
const state = getState();
98-
console.log('Update pipeline list');
99-
// debugger;
10096
pipelineStorage
10197
?.loadAll()
10298
.then((pipelines: SavedPipeline[]) => {

packages/compass-query-bar/src/stores/query-bar-reducer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,7 @@ export const saveRecentAsFavorite = (
356356
};
357357

358358
// add it in the favorite
359-
await favoriteQueryStorage?.updateAttributes(
360-
favoriteQuery._id,
361-
favoriteQuery
362-
);
359+
await favoriteQueryStorage?.saveQuery(favoriteQuery, favoriteQuery._id);
363360

364361
// update favorites
365362
void dispatch(fetchFavorites());

packages/compass-user-data/src/user-data.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,18 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
297297

298298
const response = await this.authenticatedFetch(
299299
this.getResourceUrl(
300-
`userData/${this.dataType}/${this.orgId}/${this.projectId}`
300+
`userData/${this.dataType}/${this.orgId}/${this.projectId}/${id}`
301301
),
302302
{
303303
method: 'POST',
304304
headers: {
305305
'Content-Type': 'application/json',
306306
},
307307
body: JSON.stringify({
308-
id: id,
309308
data: this.serialize(content),
310309
createdAt: new Date(),
311-
projectId: this.projectId,
312310
}),
311+
credentials: 'include',
313312
}
314313
);
315314

@@ -344,6 +343,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
344343
),
345344
{
346345
method: 'DELETE',
346+
credentials: 'include',
347347
}
348348
);
349349
if (!response.ok) {
@@ -381,6 +381,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
381381
),
382382
{
383383
method: 'GET',
384+
credentials: 'include',
384385
}
385386
);
386387
if (!response.ok) {
@@ -424,7 +425,11 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
424425
headers: {
425426
'Content-Type': 'application/json',
426427
},
427-
body: this.serialize(newData),
428+
body: JSON.stringify({
429+
data: this.serialize(newData),
430+
createdAt: new Date(),
431+
}),
432+
credentials: 'include',
428433
}
429434
);
430435
if (!response.ok) {
@@ -450,14 +455,15 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
450455
}
451456

452457
// TODO: change this depending on whether or not updateAttributes can provide all current data
453-
async readOne(id: string): Promise<z.output<T>> {
458+
async readOne(id: string): Promise<z.output<T> | undefined> {
454459
try {
455460
const getResponse = await this.authenticatedFetch(
456461
this.getResourceUrl(
457462
`userData/${this.dataType}/${this.orgId}/${this.projectId}/${id}`
458463
),
459464
{
460465
method: 'GET',
466+
credentials: 'include',
461467
}
462468
);
463469
if (!getResponse.ok) {
@@ -480,7 +486,6 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
480486
error: (error as Error).message,
481487
}
482488
);
483-
return null;
484489
}
485490
}
486491
}

packages/compass-web/src/entrypoint.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const WithStorageProviders: React.FC<{ orgId: string; projectId: string }> = ({
100100
projectId,
101101
}) => {
102102
const atlasService = useAtlasServiceContext();
103-
console.log('atlasService', atlasService);
104103
const authenticatedFetch = atlasService.authenticatedFetch.bind(atlasService);
105104
// TODO: use non-hardcoded endpoint
106105
const getResourceUrl = atlasService.tempEndpoint.bind(atlasService);

packages/my-queries-storage/src/compass-pipeline-storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class CompassPipelineStorage implements PipelineStorage {
3030
) {
3131
this.userData = new AtlasUserData(
3232
PipelineSchema,
33-
dataType,
33+
'favoriteAggregations',
3434
options.orgId,
3535
options.projectId,
3636
options.getResourceUrl,

packages/my-queries-storage/src/compass-query-storage.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export abstract class CompassQueryStorage<TSchema extends z.Schema> {
3232
options.getResourceUrl &&
3333
options.authenticatedFetch
3434
) {
35+
const type =
36+
dataType === 'RecentQueries' ? 'recentQueries' : 'favoriteQueries';
3537
this.userData = new AtlasUserData(
3638
schemaValidator,
37-
dataType,
39+
type,
3840
options.orgId,
3941
options.projectId,
4042
options.getResourceUrl,
@@ -128,10 +130,11 @@ export class CompassFavoriteQueryStorage
128130
data: Omit<
129131
z.input<typeof FavoriteQuerySchema>,
130132
'_id' | '_lastExecuted' | '_dateModified' | '_dateSaved'
131-
>
133+
>,
134+
_id?: string
132135
): Promise<void> {
133136
// TODO: verify that this doesn't break anything in compass
134-
const _id = new ObjectId().toHexString();
137+
_id ??= new ObjectId().toHexString();
135138
// this creates a favorite query that we will write to system/db
136139
const favoriteQuery = {
137140
...data,

packages/my-queries-storage/src/query-storage-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const queryProps = {
1212
};
1313

1414
const commonMetadata = {
15-
_id: z.string().uuid(),
15+
_id: z.string(),
1616
_lastExecuted: z
1717
.union([z.coerce.date(), z.number()])
1818
.transform((x) => new Date(x)),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface FavoriteQueryStorage
2323
data: Omit<
2424
z.input<typeof FavoriteQuerySchema>,
2525
'_id' | '_lastExecuted' | '_dateModified' | '_dateSaved'
26-
>
26+
>,
27+
id?: string
2728
): Promise<void>;
2829
}

0 commit comments

Comments
 (0)