1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-23 03:33:29 +00:00

Refactor StateMigrationService DI

This commit is contained in:
Thomas Rittson
2022-03-25 13:11:03 +10:00
parent e8f2ae0a7b
commit 2d15bccc65
4 changed files with 10 additions and 14 deletions

View File

@@ -308,16 +308,7 @@ import { ValidationService } from "./validation.service";
},
{
provide: StateMigrationServiceAbstraction,
useFactory: (
storageService: StorageServiceAbstraction,
secureStorageService: StorageServiceAbstraction
) =>
new StateMigrationService(
storageService,
secureStorageService,
new StateFactory(GlobalState, Account)
),
deps: [StorageServiceAbstraction, "SECURE_STORAGE"],
useClass: StateMigrationService
},
{
provide: ExportServiceAbstraction,

View File

@@ -1,5 +1,7 @@
import { InjectionToken } from '@angular/core';
import { StateFactory } from '../factories/stateFactory';
import { StorageService } from './storage.service';
export const STATE_SERVICE_USE_CACHE = new InjectionToken<boolean>('STATE_SERVICE_USE_CACHE');
export const STATE_FACTORY = new InjectionToken<StateFactory>('STATE_FACTORY');
export const SECURE_STORAGE = new InjectionToken<StorageService>('SECURE_STORAGE');

View File

@@ -34,7 +34,7 @@ import { CollectionView } from "../models/view/collectionView";
import { FolderView } from "../models/view/folderView";
import { SendView } from "../models/view/sendView";
import { STATE_FACTORY, STATE_SERVICE_USE_CACHE } from "../abstractions/injectionTokens";
import { SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE } from "../abstractions/injectionTokens";
const keys = {
global: "global",
@@ -69,7 +69,7 @@ export class StateService<
constructor(
protected storageService: StorageService,
@Inject("SECURE_STORAGE") protected secureStorageService: StorageService,
@Inject(SECURE_STORAGE) protected secureStorageService: StorageService,
protected logService: LogService,
protected stateMigrationService: StateMigrationService,
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>,

View File

@@ -1,3 +1,5 @@
import { Inject, Injectable } from '@angular/core';
import { SECURE_STORAGE, STATE_FACTORY } from '../abstractions/injectionTokens';
import { StorageService } from "../abstractions/storage.service";
import { HtmlStorageLocation } from "../enums/htmlStorageLocation";
import { KdfType } from "../enums/kdfType";
@@ -127,14 +129,15 @@ const partialKeys = {
masterKey: "_masterkey",
};
@Injectable()
export class StateMigrationService<
TGlobalState extends GlobalState = GlobalState,
TAccount extends Account = Account
> {
constructor(
protected storageService: StorageService,
protected secureStorageService: StorageService,
protected stateFactory: StateFactory<TGlobalState, TAccount>
@Inject(SECURE_STORAGE) protected secureStorageService: StorageService,
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>
) {}
async needsMigration(): Promise<boolean> {