mirror of
https://github.com/bitwarden/jslib
synced 2025-12-23 11:43:51 +00:00
Refactor StateMigrationService DI
This commit is contained in:
@@ -308,16 +308,7 @@ import { ValidationService } from "./validation.service";
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: StateMigrationServiceAbstraction,
|
provide: StateMigrationServiceAbstraction,
|
||||||
useFactory: (
|
useClass: StateMigrationService
|
||||||
storageService: StorageServiceAbstraction,
|
|
||||||
secureStorageService: StorageServiceAbstraction
|
|
||||||
) =>
|
|
||||||
new StateMigrationService(
|
|
||||||
storageService,
|
|
||||||
secureStorageService,
|
|
||||||
new StateFactory(GlobalState, Account)
|
|
||||||
),
|
|
||||||
deps: [StorageServiceAbstraction, "SECURE_STORAGE"],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: ExportServiceAbstraction,
|
provide: ExportServiceAbstraction,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { InjectionToken } from '@angular/core';
|
import { InjectionToken } from '@angular/core';
|
||||||
import { StateFactory } from '../factories/stateFactory';
|
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_SERVICE_USE_CACHE = new InjectionToken<boolean>('STATE_SERVICE_USE_CACHE');
|
||||||
export const STATE_FACTORY = new InjectionToken<StateFactory>('STATE_FACTORY');
|
export const STATE_FACTORY = new InjectionToken<StateFactory>('STATE_FACTORY');
|
||||||
|
export const SECURE_STORAGE = new InjectionToken<StorageService>('SECURE_STORAGE');
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import { CollectionView } from "../models/view/collectionView";
|
|||||||
import { FolderView } from "../models/view/folderView";
|
import { FolderView } from "../models/view/folderView";
|
||||||
import { SendView } from "../models/view/sendView";
|
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 = {
|
const keys = {
|
||||||
global: "global",
|
global: "global",
|
||||||
@@ -69,7 +69,7 @@ export class StateService<
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected storageService: StorageService,
|
protected storageService: StorageService,
|
||||||
@Inject("SECURE_STORAGE") protected secureStorageService: StorageService,
|
@Inject(SECURE_STORAGE) protected secureStorageService: StorageService,
|
||||||
protected logService: LogService,
|
protected logService: LogService,
|
||||||
protected stateMigrationService: StateMigrationService,
|
protected stateMigrationService: StateMigrationService,
|
||||||
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>,
|
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>,
|
||||||
|
|||||||
@@ -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 { StorageService } from "../abstractions/storage.service";
|
||||||
import { HtmlStorageLocation } from "../enums/htmlStorageLocation";
|
import { HtmlStorageLocation } from "../enums/htmlStorageLocation";
|
||||||
import { KdfType } from "../enums/kdfType";
|
import { KdfType } from "../enums/kdfType";
|
||||||
@@ -127,14 +129,15 @@ const partialKeys = {
|
|||||||
masterKey: "_masterkey",
|
masterKey: "_masterkey",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
export class StateMigrationService<
|
export class StateMigrationService<
|
||||||
TGlobalState extends GlobalState = GlobalState,
|
TGlobalState extends GlobalState = GlobalState,
|
||||||
TAccount extends Account = Account
|
TAccount extends Account = Account
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
protected storageService: StorageService,
|
protected storageService: StorageService,
|
||||||
protected secureStorageService: StorageService,
|
@Inject(SECURE_STORAGE) protected secureStorageService: StorageService,
|
||||||
protected stateFactory: StateFactory<TGlobalState, TAccount>
|
@Inject(STATE_FACTORY) protected stateFactory: StateFactory<TGlobalState, TAccount>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async needsMigration(): Promise<boolean> {
|
async needsMigration(): Promise<boolean> {
|
||||||
|
|||||||
Reference in New Issue
Block a user