1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-7917] Remove session sync (#9024)

* Remove session sync and MemoryStorageService

* Fix merge
This commit is contained in:
Matt Gibson
2024-05-07 13:25:49 -04:00
committed by GitHub
parent c241aba025
commit de0852431a
29 changed files with 41 additions and 902 deletions

View File

@@ -1,6 +1,6 @@
import { Observable } from "rxjs";
import { MemoryStorageOptions, StorageOptions } from "../models/domain/storage-options";
import { StorageOptions } from "../models/domain/storage-options";
export type StorageUpdateType = "save" | "remove";
export type StorageUpdate = {
@@ -24,12 +24,3 @@ export abstract class AbstractStorageService {
abstract save<T>(key: string, obj: T, options?: StorageOptions): Promise<void>;
abstract remove(key: string, options?: StorageOptions): Promise<void>;
}
export abstract class AbstractMemoryStorageService extends AbstractStorageService {
// Used to identify the service in the session sync decorator framework
static readonly TYPE = "MemoryStorageService";
readonly type = AbstractMemoryStorageService.TYPE;
abstract get<T>(key: string, options?: MemoryStorageOptions<T>): Promise<T>;
abstract getBypassCache<T>(key: string, options?: MemoryStorageOptions<T>): Promise<T>;
}

View File

@@ -1,5 +1,3 @@
import { Jsonify } from "type-fest";
import { HtmlStorageLocation, StorageLocation } from "../../enums";
export type StorageOptions = {
@@ -9,5 +7,3 @@ export type StorageOptions = {
htmlStorageLocation?: HtmlStorageLocation;
keySuffix?: string;
};
export type MemoryStorageOptions<T> = StorageOptions & { deserializer?: (obj: Jsonify<T>) => T };

View File

@@ -1,8 +1,8 @@
import { Subject } from "rxjs";
import { AbstractMemoryStorageService, StorageUpdate } from "../abstractions/storage.service";
import { AbstractStorageService, StorageUpdate } from "../abstractions/storage.service";
export class MemoryStorageService extends AbstractMemoryStorageService {
export class MemoryStorageService extends AbstractStorageService {
protected store = new Map<string, unknown>();
private updatesSubject = new Subject<StorageUpdate>();
@@ -42,8 +42,4 @@ export class MemoryStorageService extends AbstractMemoryStorageService {
this.updatesSubject.next({ key, updateType: "remove" });
return Promise.resolve();
}
getBypassCache<T>(key: string): Promise<T> {
return this.get<T>(key);
}
}

View File

@@ -14,10 +14,7 @@ import {
InitOptions,
StateService as StateServiceAbstraction,
} from "../abstractions/state.service";
import {
AbstractMemoryStorageService,
AbstractStorageService,
} from "../abstractions/storage.service";
import { AbstractStorageService } from "../abstractions/storage.service";
import { HtmlStorageLocation, StorageLocation } from "../enums";
import { StateFactory } from "../factories/state-factory";
import { Utils } from "../misc/utils";
@@ -61,7 +58,7 @@ export class StateService<
constructor(
protected storageService: AbstractStorageService,
protected secureStorageService: AbstractStorageService,
protected memoryStorageService: AbstractMemoryStorageService,
protected memoryStorageService: AbstractStorageService,
protected logService: LogService,
protected stateFactory: StateFactory<TGlobalState, TAccount>,
protected accountService: AccountService,
@@ -1111,9 +1108,10 @@ export class StateService<
}
protected async state(): Promise<State<TGlobalState, TAccount>> {
const state = await this.memoryStorageService.get<State<TGlobalState, TAccount>>(keys.state, {
deserializer: (s) => State.fromJSON(s, this.accountDeserializer),
});
let state = await this.memoryStorageService.get<State<TGlobalState, TAccount>>(keys.state);
if (this.memoryStorageService.valuesRequireDeserialization) {
state = State.fromJSON(state, this.accountDeserializer);
}
return state;
}

View File

@@ -1,13 +1,13 @@
import { Subject } from "rxjs";
import {
AbstractMemoryStorageService,
AbstractStorageService,
ObservableStorageService,
StorageUpdate,
} from "../../abstractions/storage.service";
export class MemoryStorageService
extends AbstractMemoryStorageService
extends AbstractStorageService
implements ObservableStorageService
{
protected store: Record<string, string> = {};
@@ -49,8 +49,4 @@ export class MemoryStorageService
this.updatesSubject.next({ key, updateType: "remove" });
return Promise.resolve();
}
getBypassCache<T>(key: string): Promise<T> {
return this.get<T>(key);
}
}