1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[deps] Autofill: Update prettier to v3 (#7014)

* [deps] Autofill: Update prettier to v3

* prettier formatting updates

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Prusik <jprusik@classynemesis.com>
This commit is contained in:
renovate[bot]
2023-11-29 16:15:20 -05:00
committed by GitHub
parent 4ff5f38e89
commit 28de9439be
1145 changed files with 5898 additions and 5612 deletions

View File

@@ -18,7 +18,7 @@ export interface GlobalState<T> {
*/
update: <TCombine>(
configureState: (state: T, dependency: TCombine) => T,
options?: StateUpdateOptions<T, TCombine>
options?: StateUpdateOptions<T, TCombine>,
) => Promise<T>;
/**

View File

@@ -10,14 +10,14 @@ export class DefaultDerivedUserState<TFrom, TTo> implements DerivedUserState<TTo
constructor(
private converter: Converter<TFrom, TTo>,
private encryptService: EncryptService,
private userState: UserState<TFrom>
private userState: UserState<TFrom>,
) {
this.state$ = userState.state$.pipe(
switchMap(async (from) => {
// TODO: How do I get the key?
const convertedData = await this.converter(from, new DeriveContext(null, encryptService));
return convertedData;
})
}),
);
}
}

View File

@@ -15,7 +15,7 @@ export class DefaultGlobalStateProvider implements GlobalStateProvider {
constructor(
private memoryStorage: AbstractMemoryStorageService & ObservableStorageService,
private diskStorage: AbstractStorageService & ObservableStorageService
private diskStorage: AbstractStorageService & ObservableStorageService,
) {}
get<T>(keyDefinition: KeyDefinition<T>): GlobalState<T> {
@@ -29,7 +29,7 @@ export class DefaultGlobalStateProvider implements GlobalStateProvider {
const newGlobalState = new DefaultGlobalState<T>(
keyDefinition,
this.getLocation(keyDefinition.stateDefinition.storageLocation)
this.getLocation(keyDefinition.stateDefinition.storageLocation),
);
this.globalStateCache[cacheKey] = newGlobalState;

View File

@@ -120,7 +120,7 @@ describe("DefaultGlobalState", () => {
},
{
combineLatestWith: of(combinedDependencies),
}
},
);
await awaitAsync();
@@ -140,7 +140,7 @@ describe("DefaultGlobalState", () => {
},
{
shouldUpdate: () => false,
}
},
);
expect(diskStorageService.mock.save).not.toHaveBeenCalled();

View File

@@ -32,7 +32,7 @@ export class DefaultGlobalState<T> implements GlobalState<T> {
constructor(
private keyDefinition: KeyDefinition<T>,
private chosenLocation: AbstractStorageService & ObservableStorageService
private chosenLocation: AbstractStorageService & ObservableStorageService,
) {
this.storageKey = globalKeyBuilder(this.keyDefinition);
@@ -45,10 +45,10 @@ export class DefaultGlobalState<T> implements GlobalState<T> {
return await getStoredValue(
this.storageKey,
this.chosenLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
}),
shareReplay({ bufferSize: 1, refCount: false })
shareReplay({ bufferSize: 1, refCount: false }),
);
this.state$ = defer(() => {
@@ -65,17 +65,17 @@ export class DefaultGlobalState<T> implements GlobalState<T> {
complete: () => {
storageUpdateSubscription.unsubscribe();
},
})
}),
);
}).pipe(
shareReplay({ refCount: false, bufferSize: 1 }),
filter<T>((i) => i != FAKE_DEFAULT)
filter<T>((i) => i != FAKE_DEFAULT),
);
}
async update<TCombine>(
configureState: (state: T, dependency: TCombine) => T,
options: StateUpdateOptions<T, TCombine> = {}
options: StateUpdateOptions<T, TCombine> = {},
): Promise<T> {
options = populateOptionsWithDefault(options);
const currentState = await this.getGuaranteedState();
@@ -102,7 +102,7 @@ export class DefaultGlobalState<T> implements GlobalState<T> {
return await getStoredValue(
this.storageKey,
this.chosenLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
}
}

View File

@@ -19,7 +19,7 @@ export class DefaultUserStateProvider implements UserStateProvider {
protected accountService: AccountService,
protected encryptService: EncryptService,
protected memoryStorage: AbstractMemoryStorageService & ObservableStorageService,
protected diskStorage: AbstractStorageService & ObservableStorageService
protected diskStorage: AbstractStorageService & ObservableStorageService,
) {}
get<T>(keyDefinition: KeyDefinition<T>): UserState<T> {
@@ -41,7 +41,7 @@ export class DefaultUserStateProvider implements UserStateProvider {
keyDefinition,
this.accountService,
this.encryptService,
this.getLocation(keyDefinition.stateDefinition.storageLocation)
this.getLocation(keyDefinition.stateDefinition.storageLocation),
);
}

View File

@@ -52,7 +52,7 @@ describe("DefaultUserState", () => {
testKeyDefinition,
accountService,
null, // Not testing anything with encrypt service
diskStorageService
diskStorageService,
);
});
@@ -111,17 +111,17 @@ describe("DefaultUserState", () => {
expect(diskStorageService.mock.get).toHaveBeenNthCalledWith(
1,
"user_00000000-0000-1000-a000-000000000001_fake_fake",
any()
any(),
);
expect(diskStorageService.mock.get).toHaveBeenNthCalledWith(
2,
"user_00000000-0000-1000-a000-000000000001_fake_fake",
any()
any(),
);
expect(diskStorageService.mock.get).toHaveBeenNthCalledWith(
3,
"user_00000000-0000-1000-a000-000000000002_fake_fake",
any()
any(),
);
// Should only have saved data for the first user
@@ -129,7 +129,7 @@ describe("DefaultUserState", () => {
expect(diskStorageService.mock.save).toHaveBeenNthCalledWith(
1,
"user_00000000-0000-1000-a000-000000000001_fake_fake",
any()
any(),
);
});
@@ -275,7 +275,7 @@ describe("DefaultUserState", () => {
},
{
combineLatestWith: of(combinedDependencies),
}
},
);
await awaitAsync();
@@ -295,7 +295,7 @@ describe("DefaultUserState", () => {
},
{
shouldUpdate: () => false,
}
},
);
await awaitAsync();

View File

@@ -43,15 +43,15 @@ export class DefaultUserState<T> implements UserState<T> {
protected keyDefinition: KeyDefinition<T>,
private accountService: AccountService,
private encryptService: EncryptService,
private chosenStorageLocation: AbstractStorageService & ObservableStorageService
private chosenStorageLocation: AbstractStorageService & ObservableStorageService,
) {
this.formattedKey$ = this.accountService.activeAccount$.pipe(
map((account) =>
account != null && account.id != null
? userKeyBuilder(account.id, this.keyDefinition)
: null
: null,
),
shareReplay({ bufferSize: 1, refCount: false })
shareReplay({ bufferSize: 1, refCount: false }),
);
const activeAccountData$ = this.formattedKey$.pipe(
@@ -62,11 +62,11 @@ export class DefaultUserState<T> implements UserState<T> {
return await getStoredValue(
key,
this.chosenStorageLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
}),
// Share the execution
shareReplay({ refCount: false, bufferSize: 1 })
shareReplay({ refCount: false, bufferSize: 1 }),
);
const storageUpdates$ = this.chosenStorageLocation.updates$.pipe(
@@ -79,10 +79,10 @@ export class DefaultUserState<T> implements UserState<T> {
const data = await getStoredValue(
key,
this.chosenStorageLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
return data;
})
}),
);
// Whomever subscribes to this data, should be notified of updated data
@@ -101,7 +101,7 @@ export class DefaultUserState<T> implements UserState<T> {
accountChangeSubscription.unsubscribe();
storageUpdateSubscription.unsubscribe();
},
})
}),
);
})
// I fake the generic here because I am filtering out the other union type
@@ -111,7 +111,7 @@ export class DefaultUserState<T> implements UserState<T> {
async update<TCombine>(
configureState: (state: T, dependency: TCombine) => T,
options: StateUpdateOptions<T, TCombine> = {}
options: StateUpdateOptions<T, TCombine> = {},
): Promise<T> {
options = populateOptionsWithDefault(options);
const key = await this.createKey();
@@ -133,7 +133,7 @@ export class DefaultUserState<T> implements UserState<T> {
async updateFor<TCombine>(
userId: UserId,
configureState: (state: T, dependencies: TCombine) => T,
options: StateUpdateOptions<T, TCombine> = {}
options: StateUpdateOptions<T, TCombine> = {},
): Promise<T> {
if (userId == null) {
throw new Error("Attempting to update user state, but no userId has been supplied.");
@@ -144,7 +144,7 @@ export class DefaultUserState<T> implements UserState<T> {
const currentState = await getStoredValue(
key,
this.chosenStorageLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
const combinedDependencies =
options.combineLatestWith != null
@@ -187,7 +187,7 @@ export class DefaultUserState<T> implements UserState<T> {
const value = await getStoredValue(
key,
this.chosenStorageLocation,
this.keyDefinition.deserializer
this.keyDefinition.deserializer,
);
this.stateSubject.next(value);
return value;

View File

@@ -5,7 +5,7 @@ import { AbstractStorageService } from "../../abstractions/storage.service";
export async function getStoredValue<T>(
key: string,
storage: AbstractStorageService,
deserializer: (jsonValue: Jsonify<T>) => T
deserializer: (jsonValue: Jsonify<T>) => T,
) {
if (storage.valuesRequireDeserialization) {
const jsonValue = await storage.get<Jsonify<T>>(key);

View File

@@ -47,11 +47,11 @@ describe("KeyDefinition", () => {
"fake",
{
deserializer: (value) => !value,
}
},
);
const fancyRecord = recordDefinition.deserializer(
JSON.parse(`{ "myKey": false, "mySecondKey": true }`)
JSON.parse(`{ "myKey": false, "mySecondKey": true }`),
);
expect(fancyRecord).toBeTruthy();

View File

@@ -39,11 +39,11 @@ export class KeyDefinition<T> {
constructor(
readonly stateDefinition: StateDefinition,
readonly key: string,
private readonly options: KeyDefinitionOptions<T>
private readonly options: KeyDefinitionOptions<T>,
) {
if (options.deserializer == null) {
throw new Error(
`'deserializer' is a required property on key ${stateDefinition.name} > ${key}`
`'deserializer' is a required property on key ${stateDefinition.name} > ${key}`,
);
}
}
@@ -75,7 +75,7 @@ export class KeyDefinition<T> {
stateDefinition: StateDefinition,
key: string,
// We have them provide options for the element of the array, depending on future options we add, this could get a little weird.
options: KeyDefinitionOptions<T> // The array helper forces an initialValue of an empty array
options: KeyDefinitionOptions<T>, // The array helper forces an initialValue of an empty array
) {
return new KeyDefinition<T[]>(stateDefinition, key, {
...options,
@@ -107,7 +107,7 @@ export class KeyDefinition<T> {
stateDefinition: StateDefinition,
key: string,
// We have them provide options for the value of the record, depending on future options we add, this could get a little weird.
options: KeyDefinitionOptions<T> // The array helper forces an initialValue of an empty record
options: KeyDefinitionOptions<T>, // The array helper forces an initialValue of an empty record
) {
return new KeyDefinition<Record<TKey, T>>(stateDefinition, key, {
...options,

View File

@@ -9,5 +9,8 @@ export class StateDefinition {
* @param name The name of the state, this needs to be unique from all other {@link StateDefinition}'s.
* @param storageLocation The location of where this state should be stored.
*/
constructor(readonly name: string, readonly storageLocation: StorageLocation) {}
constructor(
readonly name: string,
readonly storageLocation: StorageLocation,
) {}
}

View File

@@ -17,7 +17,7 @@ type DefinitelyTypedDefault<T, TCombine> = Omit<
export type StateUpdateOptions<T, TCombine> = Partial<DefinitelyTypedDefault<T, TCombine>>;
export function populateOptionsWithDefault<T, TCombine>(
options: StateUpdateOptions<T, TCombine>
options: StateUpdateOptions<T, TCombine>,
): StateUpdateOptions<T, TCombine> {
return {
...(DEFAULT_OPTIONS as StateUpdateOptions<T, TCombine>),

View File

@@ -9,7 +9,10 @@ import { StateUpdateOptions } from "./state-update-options";
import { DerivedUserState } from ".";
export class DeriveContext {
constructor(readonly activeUserKey: UserKey, readonly encryptService: EncryptService) {}
constructor(
readonly activeUserKey: UserKey,
readonly encryptService: EncryptService,
) {}
}
export type Converter<TFrom, TTo> = (data: TFrom, context: DeriveContext) => Promise<TTo>;
@@ -32,7 +35,7 @@ export interface UserState<T> {
*/
readonly update: <TCombine>(
configureState: (state: T, dependencies: TCombine) => T,
options?: StateUpdateOptions<T, TCombine>
options?: StateUpdateOptions<T, TCombine>,
) => Promise<T>;
/**
* Updates backing stores for the given userId, which may or may not be active.
@@ -48,7 +51,7 @@ export interface UserState<T> {
readonly updateFor: <TCombine>(
userId: UserId,
configureState: (state: T, dependencies: TCombine) => T,
options?: StateUpdateOptions<T, TCombine>
options?: StateUpdateOptions<T, TCombine>,
) => Promise<T>;
/**