1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 05:13:29 +00:00

Resolve state <-> state-test-utils circular dependency (#16093)

* Resolve state <-> state-test-utils circular dependency

* Fix type errors
This commit is contained in:
Justin Baur
2025-08-25 12:38:28 -04:00
committed by GitHub
parent 777b92660a
commit 5f7f1d1924
90 changed files with 543 additions and 500 deletions

View File

@@ -1,11 +0,0 @@
import { Observable } from "rxjs";
import { UserId } from "@bitwarden/user-core";
export abstract class ActiveUserAccessor {
/**
* Returns a stream of the current active user for the application. The stream either emits the user id for that account
* or returns null if there is no current active user.
*/
abstract activeUserId$: Observable<UserId | null>;
}

View File

@@ -1 +0,0 @@
export { DeriveDefinition } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DerivedStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DerivedState } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { GlobalStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { GlobalState } from "@bitwarden/state";

View File

@@ -1,36 +0,0 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Observable, distinctUntilChanged } from "rxjs";
import { UserId } from "../../../types/guid";
import { ActiveUserAccessor } from "../active-user.accessor";
import { UserKeyDefinition } from "../user-key-definition";
import { ActiveUserState } from "../user-state";
import { ActiveUserStateProvider, SingleUserStateProvider } from "../user-state.provider";
import { DefaultActiveUserState } from "./default-active-user-state";
export class DefaultActiveUserStateProvider implements ActiveUserStateProvider {
activeUserId$: Observable<UserId | undefined>;
constructor(
private readonly activeAccountAccessor: ActiveUserAccessor,
private readonly singleUserStateProvider: SingleUserStateProvider,
) {
this.activeUserId$ = this.activeAccountAccessor.activeUserId$.pipe(
// To avoid going to storage when we don't need to, only get updates when there is a true change.
distinctUntilChanged((a, b) => (a == null || b == null ? a == b : a === b)), // Treat null and undefined as equal
);
}
get<T>(keyDefinition: UserKeyDefinition<T>): ActiveUserState<T> {
// All other providers cache the creation of their corresponding `State` objects, this instance
// doesn't need to do that since it calls `SingleUserStateProvider` it will go through their caching
// layer, because of that, the creation of this instance is quite simple and not worth caching.
return new DefaultActiveUserState(
keyDefinition,
this.activeUserId$,
this.singleUserStateProvider,
);
}
}

View File

@@ -1 +0,0 @@
export { DefaultActiveUserState } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultDerivedStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultDerivedState } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultGlobalStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultGlobalState } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultSingleUserStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultSingleUserState } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { DefaultStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { InlineDerivedState, InlineDerivedStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { StateBase } from "@bitwarden/state";

View File

@@ -1 +1,6 @@
import { StateUpdateOptions as RequiredStateUpdateOptions } from "@bitwarden/state";
export * from "@bitwarden/state";
export { ActiveUserAccessor } from "@bitwarden/state-internal";
export type StateUpdateOptions<T, TCombine> = Partial<RequiredStateUpdateOptions<T, TCombine>>;

View File

@@ -1 +0,0 @@
export { KeyDefinition, KeyDefinitionOptions } from "@bitwarden/state";

View File

@@ -1,4 +1 @@
export { StateDefinition } from "@bitwarden/state";
// To be removed once references are updated to point to @bitwarden/storage-core
export { StorageLocation, ClientLocations } from "@bitwarden/storage-core";

View File

@@ -1,6 +0,0 @@
export {
StateEventRegistrarService,
StateEventInfo,
STATE_LOCK_EVENT,
STATE_LOGOUT_EVENT,
} from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { StateEventRunnerService } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { StateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { SerializedMemoryStorageService as MemoryStorageService } from "@bitwarden/storage-core";

View File

@@ -1 +0,0 @@
export { UserKeyDefinition, UserKeyDefinitionOptions } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { ActiveUserStateProvider, SingleUserStateProvider } from "@bitwarden/state";

View File

@@ -1 +0,0 @@
export { ActiveUserState, SingleUserState, CombinedState } from "@bitwarden/state";