mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
Require lifetime specification of user-scoped data (#8669)
* Require lifetime specification of user-scoped data * Decouple tests for different classes This coupling assumed constant interfaces with classes that isn't a guarantee and requires significant acrobatics to make types work, now that key definitions are not a consistent base. * Fix types
This commit is contained in:
@@ -3,7 +3,7 @@ import { StorageKey } from "../../types/state";
|
||||
import { Utils } from "../misc/utils";
|
||||
|
||||
import { array, record } from "./deserialization-helpers";
|
||||
import { KeyDefinition, KeyDefinitionOptions } from "./key-definition";
|
||||
import { KeyDefinitionOptions } from "./key-definition";
|
||||
import { StateDefinition } from "./state-definition";
|
||||
|
||||
export type ClearEvent = "lock" | "logout";
|
||||
@@ -14,15 +14,6 @@ export type UserKeyDefinitionOptions<T> = KeyDefinitionOptions<T> & {
|
||||
|
||||
const USER_KEY_DEFINITION_MARKER: unique symbol = Symbol("UserKeyDefinition");
|
||||
|
||||
export function isUserKeyDefinition<T>(
|
||||
keyDefinition: KeyDefinition<T> | UserKeyDefinition<T>,
|
||||
): keyDefinition is UserKeyDefinition<T> {
|
||||
return (
|
||||
USER_KEY_DEFINITION_MARKER in keyDefinition &&
|
||||
keyDefinition[USER_KEY_DEFINITION_MARKER] === true
|
||||
);
|
||||
}
|
||||
|
||||
export class UserKeyDefinition<T> {
|
||||
readonly [USER_KEY_DEFINITION_MARKER] = true;
|
||||
/**
|
||||
@@ -63,20 +54,6 @@ export class UserKeyDefinition<T> {
|
||||
return this.options.cleanupDelayMs < 0 ? 0 : this.options.cleanupDelayMs ?? 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param keyDefinition
|
||||
* @returns
|
||||
*
|
||||
* @deprecated You should not use this to convert, just create a {@link UserKeyDefinition}
|
||||
*/
|
||||
static fromBaseKeyDefinition<T>(keyDefinition: KeyDefinition<T>) {
|
||||
return new UserKeyDefinition<T>(keyDefinition.stateDefinition, keyDefinition.key, {
|
||||
...keyDefinition["options"],
|
||||
clearOn: [], // Default to not clearing
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link UserKeyDefinition} for state that is an array.
|
||||
* @param stateDefinition The state definition to be added to the UserKeyDefinition
|
||||
|
||||
Reference in New Issue
Block a user