mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +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:
@@ -20,12 +20,12 @@ export type MinVersion = typeof MIN_VERSION;
|
||||
|
||||
export async function migrate(
|
||||
storageService: AbstractStorageService,
|
||||
logService: LogService
|
||||
logService: LogService,
|
||||
): Promise<void> {
|
||||
const migrationHelper = new MigrationHelper(
|
||||
await currentVersion(storageService, logService),
|
||||
storageService,
|
||||
logService
|
||||
logService,
|
||||
);
|
||||
if (migrationHelper.currentVersion < 0) {
|
||||
// Cannot determine state, assuming empty so we don't repeatedly apply a migration.
|
||||
@@ -46,7 +46,7 @@ export async function migrate(
|
||||
|
||||
export async function currentVersion(
|
||||
storageService: AbstractStorageService,
|
||||
logService: LogService
|
||||
logService: LogService,
|
||||
) {
|
||||
let state = await storageService.get<number>("stateVersion");
|
||||
if (state == null) {
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("MigrationBuilder", () => {
|
||||
it("should throw if instantiated incorrectly", () => {
|
||||
expect(() => MigrationBuilder.create().with(TestMigrator, null, null)).toThrow();
|
||||
expect(() =>
|
||||
MigrationBuilder.create().with(TestMigrator, 0, 1).with(TestBadMigrator, 1, 0)
|
||||
MigrationBuilder.create().with(TestMigrator, 0, 1).with(TestBadMigrator, 1, 0),
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class MigrationBuilder<TCurrent extends number = 0> {
|
||||
}
|
||||
|
||||
private constructor(
|
||||
private migrations: readonly { migrator: Migrator<number, number>; direction: Direction }[]
|
||||
private migrations: readonly { migrator: Migrator<number, number>; direction: Direction }[],
|
||||
) {}
|
||||
|
||||
/** Add a migrator to the MigrationBuilder. Types are updated such that the chained MigrationBuilder must currently be
|
||||
@@ -26,7 +26,7 @@ export class MigrationBuilder<TCurrent extends number = 0> {
|
||||
with<
|
||||
TMigrator extends Migrator<number, number>,
|
||||
TFrom extends VersionFrom<TMigrator> & TCurrent,
|
||||
TTo extends VersionTo<TMigrator>
|
||||
TTo extends VersionTo<TMigrator>,
|
||||
>(
|
||||
...migrate: [new () => TMigrator] | [new (from: TFrom, to: TTo) => TMigrator, TFrom, TTo]
|
||||
): MigrationBuilder<TTo> {
|
||||
@@ -45,7 +45,7 @@ export class MigrationBuilder<TCurrent extends number = 0> {
|
||||
rollback<
|
||||
TMigrator extends Migrator<number, number>,
|
||||
TFrom extends VersionFrom<TMigrator>,
|
||||
TTo extends VersionTo<TMigrator> & TCurrent
|
||||
TTo extends VersionTo<TMigrator> & TCurrent,
|
||||
>(
|
||||
...migrate: [new () => TMigrator] | [new (from: TFrom, to: TTo) => TMigrator, TTo, TFrom]
|
||||
): MigrationBuilder<TFrom> {
|
||||
@@ -62,17 +62,17 @@ export class MigrationBuilder<TCurrent extends number = 0> {
|
||||
promise.then(async () => {
|
||||
await this.runMigrator(migrator.migrator, helper, migrator.direction);
|
||||
}),
|
||||
Promise.resolve()
|
||||
Promise.resolve(),
|
||||
);
|
||||
}
|
||||
|
||||
private addMigrator<
|
||||
TMigrator extends Migrator<number, number>,
|
||||
TFrom extends VersionFrom<TMigrator> & TCurrent,
|
||||
TTo extends VersionTo<TMigrator>
|
||||
TTo extends VersionTo<TMigrator>,
|
||||
>(
|
||||
migrate: [new () => TMigrator] | [new (from: TFrom, to: TTo) => TMigrator, TFrom, TTo],
|
||||
direction: Direction = "up"
|
||||
direction: Direction = "up",
|
||||
) {
|
||||
const newMigration =
|
||||
migrate.length === 1
|
||||
@@ -85,21 +85,21 @@ export class MigrationBuilder<TCurrent extends number = 0> {
|
||||
private async runMigrator(
|
||||
migrator: Migrator<number, number>,
|
||||
helper: MigrationHelper,
|
||||
direction: Direction
|
||||
direction: Direction,
|
||||
): Promise<void> {
|
||||
const shouldMigrate = await migrator.shouldMigrate(helper, direction);
|
||||
helper.info(
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) should migrate: ${shouldMigrate} - ${direction}`
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) should migrate: ${shouldMigrate} - ${direction}`,
|
||||
);
|
||||
if (shouldMigrate) {
|
||||
const method = direction === "up" ? migrator.migrate : migrator.rollback;
|
||||
await method.bind(migrator)(helper);
|
||||
helper.info(
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) migrated - ${direction}`
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) migrated - ${direction}`,
|
||||
);
|
||||
await migrator.updateVersion(helper, direction);
|
||||
helper.info(
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) updated version - ${direction}`
|
||||
`Migrator ${migrator.constructor.name} (to version ${migrator.toVersion}) updated version - ${direction}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ describe("RemoveLegacyEtmKeyMigrator", () => {
|
||||
|
||||
it("should handle missing authenticatedAccounts", async () => {
|
||||
storage.get.mockImplementation((key) =>
|
||||
key === "authenticatedAccounts" ? undefined : (exampleJSON as any)[key]
|
||||
key === "authenticatedAccounts" ? undefined : (exampleJSON as any)[key],
|
||||
);
|
||||
const accounts = await sut.getAccounts();
|
||||
expect(accounts).toEqual([]);
|
||||
|
||||
@@ -7,7 +7,7 @@ export class MigrationHelper {
|
||||
constructor(
|
||||
public currentVersion: number,
|
||||
private storageService: AbstractStorageService,
|
||||
public logService: LogService
|
||||
public logService: LogService,
|
||||
) {}
|
||||
|
||||
get<T>(key: string): Promise<T> {
|
||||
@@ -31,7 +31,7 @@ export class MigrationHelper {
|
||||
userIds.map(async (userId) => ({
|
||||
userId,
|
||||
account: await this.get<ExpectedAccountType>(userId),
|
||||
}))
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ describe("RemoveLegacyEtmKeyMigrator", () => {
|
||||
await sut.migrate(helper);
|
||||
expect(helper.set).not.toHaveBeenCalledWith(
|
||||
matches((s) => s != "global"),
|
||||
any()
|
||||
any(),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -95,7 +95,7 @@ describe("RemoveLegacyEtmKeyMigrator", () => {
|
||||
"global",
|
||||
Object.assign({}, exampleJSON().global, {
|
||||
stateVersion: 7,
|
||||
})
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("moveStateVersion", () => {
|
||||
it("should throw if state version not found", async () => {
|
||||
helper.get.mockReturnValue({ otherStuff: "otherStuff1" } as any);
|
||||
await expect(sut.migrate(helper)).rejects.toThrow(
|
||||
"Migration failed, state version not found"
|
||||
"Migration failed, state version not found",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ type TestState = { authenticatedAccounts: string[] } & { [key: string]: unknown
|
||||
// This could become a helper available to anyone
|
||||
const runMigrator = async <TMigrator extends Migrator<number, number>>(
|
||||
migrator: TMigrator,
|
||||
initalData?: Record<string, unknown>
|
||||
initalData?: Record<string, unknown>,
|
||||
): Promise<Record<string, unknown>> => {
|
||||
const fakeStorageService = new FakeStorageService(initalData);
|
||||
const helper = new MigrationHelper(migrator.fromVersion, fakeStorageService, mock());
|
||||
|
||||
@@ -27,7 +27,7 @@ export class MoveBrowserSettingsToGlobal extends Migrator<8, 9> {
|
||||
tryAddSetting(
|
||||
accounts: { userId: string; account: ExpectedAccountType }[],
|
||||
accountSelector: (account: ExpectedAccountType) => boolean | undefined,
|
||||
globalSetter: (value: boolean | undefined) => void
|
||||
globalSetter: (value: boolean | undefined) => void,
|
||||
): void {
|
||||
const hasValue = accounts.some(({ account }) => {
|
||||
return accountSelector(account) !== undefined;
|
||||
@@ -65,19 +65,19 @@ export class MoveBrowserSettingsToGlobal extends Migrator<8, 9> {
|
||||
this.tryAddSetting(
|
||||
accounts,
|
||||
(a) => a.settings?.disableAddLoginNotification,
|
||||
(v) => (targetGlobalState.disableAddLoginNotification = v)
|
||||
(v) => (targetGlobalState.disableAddLoginNotification = v),
|
||||
);
|
||||
|
||||
this.tryAddSetting(
|
||||
accounts,
|
||||
(a) => a.settings?.disableChangedPasswordNotification,
|
||||
(v) => (targetGlobalState.disableChangedPasswordNotification = v)
|
||||
(v) => (targetGlobalState.disableChangedPasswordNotification = v),
|
||||
);
|
||||
|
||||
this.tryAddSetting(
|
||||
accounts,
|
||||
(a) => a.settings?.disableContextMenuItem,
|
||||
(v) => (targetGlobalState.disableContextMenuItem = v)
|
||||
(v) => (targetGlobalState.disableContextMenuItem = v),
|
||||
);
|
||||
|
||||
await helper.set<TargetGlobalState>("global", {
|
||||
@@ -92,7 +92,7 @@ export class MoveBrowserSettingsToGlobal extends Migrator<8, 9> {
|
||||
delete account.settings?.disableContextMenuItem;
|
||||
delete account.settings?.neverDomains;
|
||||
await helper.set(userId, account);
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@ export type VersionTo<T> = T extends Migrator<number, infer TTo>
|
||||
export type Direction = "up" | "down";
|
||||
|
||||
export abstract class Migrator<TFrom extends number, TTo extends number> {
|
||||
constructor(public fromVersion: TFrom, public toVersion: TTo) {
|
||||
constructor(
|
||||
public fromVersion: TFrom,
|
||||
public toVersion: TTo,
|
||||
) {
|
||||
if (fromVersion == null || toVersion == null) {
|
||||
throw new Error("Invalid migration");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user