mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
Add missing state provider factories (#7262)
This commit is contained in:
parent
6199e58532
commit
bc1f93d098
@ -0,0 +1,43 @@
|
|||||||
|
import { ActiveUserStateProvider } from "@bitwarden/common/platform/state";
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
|
||||||
|
import { DefaultActiveUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-active-user-state.provider";
|
||||||
|
|
||||||
|
import {
|
||||||
|
AccountServiceInitOptions,
|
||||||
|
accountServiceFactory,
|
||||||
|
} from "../../../auth/background/service-factories/account-service.factory";
|
||||||
|
|
||||||
|
import { EncryptServiceInitOptions, encryptServiceFactory } from "./encrypt-service.factory";
|
||||||
|
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||||
|
import {
|
||||||
|
DiskStorageServiceInitOptions,
|
||||||
|
MemoryStorageServiceInitOptions,
|
||||||
|
observableDiskStorageServiceFactory,
|
||||||
|
observableMemoryStorageServiceFactory,
|
||||||
|
} from "./storage-service.factory";
|
||||||
|
|
||||||
|
type ActiveUserStateProviderFactory = FactoryOptions;
|
||||||
|
|
||||||
|
export type ActiveUserStateProviderInitOptions = ActiveUserStateProviderFactory &
|
||||||
|
AccountServiceInitOptions &
|
||||||
|
EncryptServiceInitOptions &
|
||||||
|
MemoryStorageServiceInitOptions &
|
||||||
|
DiskStorageServiceInitOptions;
|
||||||
|
|
||||||
|
export async function activeUserStateProviderFactory(
|
||||||
|
cache: { activeUserStateProvider?: ActiveUserStateProvider } & CachedServices,
|
||||||
|
opts: ActiveUserStateProviderInitOptions,
|
||||||
|
): Promise<ActiveUserStateProvider> {
|
||||||
|
return factory(
|
||||||
|
cache,
|
||||||
|
"activeUserStateProvider",
|
||||||
|
opts,
|
||||||
|
async () =>
|
||||||
|
new DefaultActiveUserStateProvider(
|
||||||
|
await accountServiceFactory(cache, opts),
|
||||||
|
await encryptServiceFactory(cache, opts),
|
||||||
|
await observableMemoryStorageServiceFactory(cache, opts),
|
||||||
|
await observableDiskStorageServiceFactory(cache, opts),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
import { SingleUserStateProvider } from "@bitwarden/common/platform/state";
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
|
||||||
|
import { DefaultSingleUserStateProvider } from "@bitwarden/common/platform/state/implementations/default-single-user-state.provider";
|
||||||
|
|
||||||
|
import { EncryptServiceInitOptions, encryptServiceFactory } from "./encrypt-service.factory";
|
||||||
|
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||||
|
import {
|
||||||
|
DiskStorageServiceInitOptions,
|
||||||
|
MemoryStorageServiceInitOptions,
|
||||||
|
observableDiskStorageServiceFactory,
|
||||||
|
observableMemoryStorageServiceFactory,
|
||||||
|
} from "./storage-service.factory";
|
||||||
|
|
||||||
|
type SingleUserStateProviderFactoryOptions = FactoryOptions;
|
||||||
|
|
||||||
|
export type SingleUserStateProviderInitOptions = SingleUserStateProviderFactoryOptions &
|
||||||
|
EncryptServiceInitOptions &
|
||||||
|
MemoryStorageServiceInitOptions &
|
||||||
|
DiskStorageServiceInitOptions;
|
||||||
|
|
||||||
|
export async function singleUserStateProviderFactory(
|
||||||
|
cache: { singleUserStateProvider?: SingleUserStateProvider } & CachedServices,
|
||||||
|
opts: SingleUserStateProviderInitOptions,
|
||||||
|
): Promise<SingleUserStateProvider> {
|
||||||
|
return factory(
|
||||||
|
cache,
|
||||||
|
"singleUserStateProvider",
|
||||||
|
opts,
|
||||||
|
async () =>
|
||||||
|
new DefaultSingleUserStateProvider(
|
||||||
|
await encryptServiceFactory(cache, opts),
|
||||||
|
await observableMemoryStorageServiceFactory(cache, opts),
|
||||||
|
await observableDiskStorageServiceFactory(cache, opts),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
import { StateProvider } from "@bitwarden/common/platform/state";
|
||||||
|
// eslint-disable-next-line import/no-restricted-paths -- We need the implementation to inject, but generally this should not be accessed
|
||||||
|
import { DefaultStateProvider } from "@bitwarden/common/platform/state/implementations/default-state.provider";
|
||||||
|
|
||||||
|
import {
|
||||||
|
ActiveUserStateProviderInitOptions,
|
||||||
|
activeUserStateProviderFactory,
|
||||||
|
} from "./active-user-state-provider.factory";
|
||||||
|
import { CachedServices, FactoryOptions, factory } from "./factory-options";
|
||||||
|
import {
|
||||||
|
GlobalStateProviderInitOptions,
|
||||||
|
globalStateProviderFactory,
|
||||||
|
} from "./global-state-provider.factory";
|
||||||
|
import {
|
||||||
|
SingleUserStateProviderInitOptions,
|
||||||
|
singleUserStateProviderFactory,
|
||||||
|
} from "./single-user-state-provider.factory";
|
||||||
|
|
||||||
|
type StateProviderFactoryOptions = FactoryOptions;
|
||||||
|
|
||||||
|
export type StateProviderInitOptions = StateProviderFactoryOptions &
|
||||||
|
GlobalStateProviderInitOptions &
|
||||||
|
ActiveUserStateProviderInitOptions &
|
||||||
|
SingleUserStateProviderInitOptions;
|
||||||
|
|
||||||
|
export async function stateProviderFactory(
|
||||||
|
cache: { stateProvider?: StateProvider } & CachedServices,
|
||||||
|
opts: StateProviderInitOptions,
|
||||||
|
): Promise<StateProvider> {
|
||||||
|
return factory(
|
||||||
|
cache,
|
||||||
|
"stateProvider",
|
||||||
|
opts,
|
||||||
|
async () =>
|
||||||
|
new DefaultStateProvider(
|
||||||
|
await activeUserStateProviderFactory(cache, opts),
|
||||||
|
await singleUserStateProviderFactory(cache, opts),
|
||||||
|
await globalStateProviderFactory(cache, opts),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user