[PM-6426] Aligning the implementation with our code guidelines for Angular components

This commit is contained in:
Cesar Gonzalez 2024-04-17 11:33:01 -05:00
parent 1bd44d11c3
commit 55fc6afb5d
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
8 changed files with 21 additions and 20 deletions

View File

@ -3,7 +3,7 @@ import { firstValueFrom, map, Observable } from "rxjs";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { TaskIdentifier } from "@bitwarden/common/platform/abstractions/task-scheduler.service"; import { TaskIdentifier } from "@bitwarden/common/platform/abstractions/task-scheduler.service";
import { ScheduledTaskName } from "@bitwarden/common/platform/enums/scheduled-task-name.enum"; import { ScheduledTaskName } from "@bitwarden/common/platform/enums/scheduled-task-name.enum";
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service";
import { import {
TASK_SCHEDULER_DISK, TASK_SCHEDULER_DISK,
GlobalState, GlobalState,
@ -23,7 +23,7 @@ const ACTIVE_ALARMS = new KeyDefinition(TASK_SCHEDULER_DISK, "activeAlarms", {
}); });
export class BrowserTaskSchedulerService export class BrowserTaskSchedulerService
extends TaskSchedulerService extends DefaultTaskSchedulerService
implements BrowserTaskSchedulerServiceInterface implements BrowserTaskSchedulerServiceInterface
{ {
private activeAlarmsState: GlobalState<ActiveAlarm[]>; private activeAlarmsState: GlobalState<ActiveAlarm[]>;

View File

@ -64,12 +64,12 @@ import {
AbstractStorageService, AbstractStorageService,
ObservableStorageService, ObservableStorageService,
} from "@bitwarden/common/platform/abstractions/storage.service"; } from "@bitwarden/common/platform/abstractions/storage.service";
import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
import { ContainerService } from "@bitwarden/common/platform/services/container.service"; import { ContainerService } from "@bitwarden/common/platform/services/container.service";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
import { import {
DerivedStateProvider, DerivedStateProvider,

View File

@ -40,13 +40,14 @@ import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwar
import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service";
import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service";
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service";
import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service"; import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
import { SystemService } from "@bitwarden/common/platform/services/system.service"; import { SystemService } from "@bitwarden/common/platform/services/system.service";
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state"; import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state";
// eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage // eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage
import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service"; import { MemoryStorageService as MemoryStorageServiceForStateProviders } from "@bitwarden/common/platform/state/storage/memory-storage.service";
@ -253,6 +254,7 @@ const safeProviders: SafeProvider[] = [
}), }),
safeProvider({ safeProvider({
provide: TaskSchedulerService, provide: TaskSchedulerService,
useClass: DefaultTaskSchedulerService,
deps: [], deps: [],
}), }),
]; ];

View File

@ -130,6 +130,7 @@ import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/comm
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
import { TaskSchedulerService } from "@bitwarden/common/platform/abstractions/task-scheduler.service";
import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service"; import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service";
import { import {
BiometricStateService, BiometricStateService,
@ -147,6 +148,7 @@ import { CryptoService } from "@bitwarden/common/platform/services/crypto.servic
import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation"; import { EncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/encrypt.service.implementation";
import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation"; import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation";
import { DefaultEnvironmentService } from "@bitwarden/common/platform/services/default-environment.service"; import { DefaultEnvironmentService } from "@bitwarden/common/platform/services/default-environment.service";
import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service";
import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service"; import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service";
import { KeyGenerationService } from "@bitwarden/common/platform/services/key-generation.service"; import { KeyGenerationService } from "@bitwarden/common/platform/services/key-generation.service";
import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service"; import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service";
@ -154,7 +156,6 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r
import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service"; import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service";
import { StateService } from "@bitwarden/common/platform/services/state.service"; import { StateService } from "@bitwarden/common/platform/services/state.service";
import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider"; import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider";
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service";
import { ValidationService } from "@bitwarden/common/platform/services/validation.service"; import { ValidationService } from "@bitwarden/common/platform/services/validation.service";
import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service";
import { import {
@ -1128,6 +1129,7 @@ const safeProviders: SafeProvider[] = [
}), }),
safeProvider({ safeProvider({
provide: TaskSchedulerService, provide: TaskSchedulerService,
useClass: DefaultTaskSchedulerService,
deps: [], deps: [],
}), }),
safeProvider({ safeProvider({

View File

@ -23,7 +23,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { KdfType } from "@bitwarden/common/platform/enums"; import { KdfType } from "@bitwarden/common/platform/enums";
import { TaskSchedulerService } from "@bitwarden/common/platform/services/task-scheduler.service"; import { DefaultTaskSchedulerService } from "@bitwarden/common/platform/services/default-task-scheduler.service";
import { import {
FakeAccountService, FakeAccountService,
FakeGlobalState, FakeGlobalState,
@ -67,7 +67,7 @@ describe("LoginStrategyService", () => {
let authRequestService: MockProxy<AuthRequestServiceAbstraction>; let authRequestService: MockProxy<AuthRequestServiceAbstraction>;
let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>; let userDecryptionOptionsService: MockProxy<InternalUserDecryptionOptionsServiceAbstraction>;
let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>; let billingAccountProfileStateService: MockProxy<BillingAccountProfileStateService>;
let taskSchedulerService: MockProxy<TaskSchedulerService>; let taskSchedulerService: MockProxy<DefaultTaskSchedulerService>;
let stateProvider: FakeGlobalStateProvider; let stateProvider: FakeGlobalStateProvider;
let loginStrategyCacheExpirationState: FakeGlobalState<Date | null>; let loginStrategyCacheExpirationState: FakeGlobalState<Date | null>;
@ -97,7 +97,7 @@ describe("LoginStrategyService", () => {
userDecryptionOptionsService = mock<UserDecryptionOptionsService>(); userDecryptionOptionsService = mock<UserDecryptionOptionsService>();
billingAccountProfileStateService = mock<BillingAccountProfileStateService>(); billingAccountProfileStateService = mock<BillingAccountProfileStateService>();
stateProvider = new FakeGlobalStateProvider(); stateProvider = new FakeGlobalStateProvider();
taskSchedulerService = mock<TaskSchedulerService>(); taskSchedulerService = mock<DefaultTaskSchedulerService>();
sut = new LoginStrategyService( sut = new LoginStrategyService(
accountService, accountService,

View File

@ -6,17 +6,17 @@ export type TaskIdentifier = {
intervalId?: number | NodeJS.Timeout; intervalId?: number | NodeJS.Timeout;
}; };
export interface TaskSchedulerService { export abstract class TaskSchedulerService {
setTimeout( abstract setTimeout(
callback: () => void, callback: () => void,
delayInMs: number, delayInMs: number,
taskName?: ScheduledTaskName, taskName?: ScheduledTaskName,
): Promise<number | NodeJS.Timeout>; ): Promise<number | NodeJS.Timeout>;
setInterval( abstract setInterval(
callback: () => void, callback: () => void,
intervalInMs: number, intervalInMs: number,
taskName?: ScheduledTaskName, taskName?: ScheduledTaskName,
initialDelayInMs?: number, initialDelayInMs?: number,
): Promise<number | NodeJS.Timeout>; ): Promise<number | NodeJS.Timeout>;
clearScheduledTask(taskIdentifier: TaskIdentifier): Promise<void>; abstract clearScheduledTask(taskIdentifier: TaskIdentifier): Promise<void>;
} }

View File

@ -1,14 +1,14 @@
import { TaskSchedulerService } from "./task-scheduler.service"; import { DefaultTaskSchedulerService } from "./default-task-scheduler.service";
describe("TaskSchedulerService", () => { describe("TaskSchedulerService", () => {
const callback = jest.fn(); const callback = jest.fn();
const delayInMs = 1000; const delayInMs = 1000;
const intervalInMs = 1100; const intervalInMs = 1100;
let taskSchedulerService: TaskSchedulerService; let taskSchedulerService: DefaultTaskSchedulerService;
beforeEach(() => { beforeEach(() => {
jest.useFakeTimers(); jest.useFakeTimers();
taskSchedulerService = new TaskSchedulerService(); taskSchedulerService = new DefaultTaskSchedulerService();
}); });
afterEach(() => { afterEach(() => {

View File

@ -1,10 +1,7 @@
import { import { TaskIdentifier, TaskSchedulerService } from "../abstractions/task-scheduler.service";
TaskIdentifier,
TaskSchedulerService as TaskSchedulerServiceInterface,
} from "../abstractions/task-scheduler.service";
import { ScheduledTaskName } from "../enums/scheduled-task-name.enum"; import { ScheduledTaskName } from "../enums/scheduled-task-name.enum";
export class TaskSchedulerService implements TaskSchedulerServiceInterface { export class DefaultTaskSchedulerService extends TaskSchedulerService {
/** /**
* Sets a timeout and returns the timeout id. * Sets a timeout and returns the timeout id.
* *