Skip to content

Commit 31a8643

Browse files
committed
fix: change updateAttributes return type to boolean
1 parent 18240da commit 31a8643

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export abstract class IUserData<T extends z.Schema> {
9393
abstract updateAttributes(
9494
id: string,
9595
data: Partial<z.input<T>>
96-
): Promise<z.output<T>>;
96+
): Promise<boolean>;
9797
}
9898

9999
export class FileUserData<T extends z.Schema> extends IUserData<T> {
@@ -324,12 +324,16 @@ export class FileUserData<T extends z.Schema> extends IUserData<T> {
324324
async updateAttributes(
325325
id: string,
326326
data: Partial<z.input<T>>
327-
): Promise<z.output<T>> {
328-
await this.write(id, {
329-
...((await this.readOne(id)) ?? {}),
330-
...data,
331-
});
332-
return await this.readOne(id);
327+
): Promise<boolean> {
328+
try {
329+
await this.write(id, {
330+
...((await this.readOne(id)) ?? {}),
331+
...data,
332+
});
333+
return true;
334+
} catch {
335+
return false;
336+
}
333337
}
334338
}
335339

@@ -461,7 +465,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
461465
async updateAttributes(
462466
id: string,
463467
data: Partial<z.input<T>>
464-
): Promise<z.output<T>> {
468+
): Promise<boolean> {
465469
try {
466470
const response = await this.authenticatedFetch(this.getUrl() + `/${id}`, {
467471
method: 'PUT',
@@ -475,7 +479,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
475479
`Failed to update data: ${response.status} ${response.statusText}`
476480
);
477481
}
478-
return this.validator.parse(data);
482+
return true;
479483
} catch (error) {
480484
log.error(
481485
mongoLogId(1_001_000_365),
@@ -486,7 +490,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
486490
error: (error as Error).message,
487491
}
488492
);
489-
throw new Error('Failed to update data');
493+
return false;
490494
}
491495
}
492496

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export abstract class CompassQueryStorage<TSchema extends z.Schema> {
4949
async updateAttributes(
5050
id: string,
5151
data: Partial<z.input<TSchema>>
52-
): Promise<z.output<TSchema>> {
52+
): Promise<boolean> {
5353
return await this.userData.updateAttributes(id, data);
5454
}
5555

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66

77
interface QueryStorage<T extends typeof RecentQuerySchema> {
88
loadAll(namespace?: string): Promise<z.output<T>[]>;
9-
updateAttributes(id: string, data: Partial<z.input<T>>): Promise<z.output<T>>;
9+
updateAttributes(id: string, data: Partial<z.input<T>>): Promise<boolean>;
1010
delete(id: string): Promise<boolean>;
1111
}
1212

0 commit comments

Comments
 (0)