From a94f94a17feedff2481a42013c43c3eb097790d6 Mon Sep 17 00:00:00 2001 From: Mathieu Collette Date: Fri, 11 Oct 2024 21:06:03 +0200 Subject: [PATCH] refactor: env variables --- .../server/pathway/application/src/index.ts | 2 +- .../service/initialize-pathway.service.ts | 2 +- .../pathway/infrastructure/src/index.ts | 8 ++---- ...ay-persistence-infrastructure.constants.ts | 28 +++++++++++++++++++ ...thway-persistence-infrastructure.module.ts | 27 ++---------------- ...athway-persistence-infrastructure.types.ts | 1 + .../initialize-pathway.controller.ts | 4 +-- ...alize-pathway-interface-adapters.module.ts | 6 ++-- .../server/pathway/presenters/src/index.ts | 8 ++---- .../src/lib/pathway-presenters.constants.ts | 8 ++++++ .../src/lib/pathway-presenters.module.ts | 11 ++------ .../src/lib/pathway-presenters.types.ts | 1 + 12 files changed, 56 insertions(+), 50 deletions(-) create mode 100644 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts create mode 100644 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts create mode 100644 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts create mode 100644 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts diff --git a/libs/pathway-design/server/pathway/application/src/index.ts b/libs/pathway-design/server/pathway/application/src/index.ts index 5634ae43..82ff385e 100644 --- a/libs/pathway-design/server/pathway/application/src/index.ts +++ b/libs/pathway-design/server/pathway/application/src/index.ts @@ -1,6 +1,6 @@ export { PDSPAInitializePathwayCommand } from './lib/initialize/command/initialize-pathway.command'; export { PDSPAInitializePathwayCommandHandler } from './lib/initialize/command/initialize-pathway.command-handler'; -export { PDSPAInitializePathwayService } from './lib/initialize/service/initialize-pathway.service'; +export { PDSPA_InitializePathwayService } from './lib/initialize/service/initialize-pathway.service'; export { PDSPAIUInitializePathwayUsecase } from './lib/initialize/usecase/initialize-pathway.usecase'; export { PDSPAChangeTitlePathwayCommand } from './lib/change-title/command/change-title-pathway.command'; diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts index e4c2888e..1b849447 100644 --- a/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts @@ -5,7 +5,7 @@ import { CommandBus } from '@nestjs/cqrs'; import type { PDSPAInitializePathwayCommand } from '../command/initialize-pathway.command'; @Injectable() -export class PDSPAInitializePathwayService { +export class PDSPA_InitializePathwayService { constructor(private readonly commandBus: CommandBus) {} init(pDSPAInitializePathwayCommand: PDSPAInitializePathwayCommand) { diff --git a/libs/pathway-design/server/pathway/infrastructure/src/index.ts b/libs/pathway-design/server/pathway/infrastructure/src/index.ts index d0615b4a..93d2bda9 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/index.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/index.ts @@ -1,5 +1,3 @@ -export { - PDSPIPPathwayPersistenceInfrastructureModule, - PDSPIPPersistenceDriverAuthorized, - pDSPIPPersistenceKeys, -} from './lib/persistence/pathway-persistence-infrastructure.module'; +export { pDSPIPPersistenceKeys } from './lib/persistence/pathway-persistence-infrastructure.constants'; +export { PDSPIPPathwayPersistenceInfrastructureModule } from './lib/persistence/pathway-persistence-infrastructure.module'; +export { PDSPIPPersistenceDriverAuthorized } from './lib/persistence/pathway-persistence-infrastructure.types'; diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts new file mode 100644 index 00000000..b6e7dd65 --- /dev/null +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts @@ -0,0 +1,28 @@ +import { + PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, + PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, +} from '@bewoak/pathway-design-server-pathway-business'; +import type { Provider } from '@nestjs/common'; +import { ChangeTitlePathwayInMemoryPersistence } from './change-title/in-memory/change-title-pathway-in-memory.persistence'; +import { PathwayInMemoryRepository } from './common/in-memory/repositories/in-memory-pathway.repository'; +import { InitializePathwayInMemoryPersistence } from './initialize/in-memory/initialize-pathway-in-memory.persistence'; +import type { PDSPIPPersistenceDriverAuthorized } from './pathway-persistence-infrastructure.types'; + +export const persistenceProvidersMap: Record = { + inMemory: [ + InitializePathwayInMemoryPersistence, + { + provide: PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, + useExisting: InitializePathwayInMemoryPersistence, + }, + ChangeTitlePathwayInMemoryPersistence, + { + provide: PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, + useExisting: ChangeTitlePathwayInMemoryPersistence, + }, + PathwayInMemoryRepository, + ], + orm: [], +}; + +export const pDSPIPPersistenceKeys = Object.keys(persistenceProvidersMap) as [PDSPIPPersistenceDriverAuthorized]; diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts index b1185634..b259aae2 100644 --- a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts @@ -1,32 +1,11 @@ -import { Module, type Provider } from '@nestjs/common'; +import { Module } from '@nestjs/common'; import { PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, } from '@bewoak/pathway-design-server-pathway-business'; -import { ChangeTitlePathwayInMemoryPersistence } from './change-title/in-memory/change-title-pathway-in-memory.persistence'; -import { PathwayInMemoryRepository } from './common/in-memory/repositories/in-memory-pathway.repository'; -import { InitializePathwayInMemoryPersistence } from './initialize/in-memory/initialize-pathway-in-memory.persistence'; - -const persistenceProvidersMap: Record<'inMemory', Provider[]> = { - inMemory: [ - InitializePathwayInMemoryPersistence, - { - provide: PDSPBP_INITIALIZE_PATHWAY_PERSISTENCE_PORT, - useExisting: InitializePathwayInMemoryPersistence, - }, - ChangeTitlePathwayInMemoryPersistence, - { - provide: PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, - useExisting: ChangeTitlePathwayInMemoryPersistence, - }, - PathwayInMemoryRepository, - ], -}; - -export const pDSPIPPersistenceKeys = Object.keys(persistenceProvidersMap) as [PDSPIPPersistenceDriverAuthorized]; - -export type PDSPIPPersistenceDriverAuthorized = keyof typeof persistenceProvidersMap; +import { persistenceProvidersMap } from './pathway-persistence-infrastructure.constants'; +import type { PDSPIPPersistenceDriverAuthorized } from './pathway-persistence-infrastructure.types'; @Module({}) // biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module diff --git a/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts new file mode 100644 index 00000000..2d7901af --- /dev/null +++ b/libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts @@ -0,0 +1 @@ +export type PDSPIPPersistenceDriverAuthorized = 'inMemory' | 'orm'; diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts index 008d2ac0..2aa201c9 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts @@ -1,5 +1,5 @@ // biome-ignore lint/style/useImportType: -import { PDSPAInitializePathwayCommand, PDSPAInitializePathwayService } from '@bewoak/pathway-design-server-pathway-application'; +import { PDSPAInitializePathwayCommand, PDSPA_InitializePathwayService } from '@bewoak/pathway-design-server-pathway-application'; import { Body, Controller, HttpStatus, Post, UsePipes, ValidationPipe } from '@nestjs/common'; import { ApiBadRequestResponse, ApiCreatedResponse, ApiTags } from '@nestjs/swagger'; // biome-ignore lint/style/useImportType: @@ -17,7 +17,7 @@ import { InitializedPathwayResponseBodyDto } from '../dtos/response/body/respons path: 'pathway', }) export class InitializePathwayController { - constructor(private readonly pDSPAInitializePathwayService: PDSPAInitializePathwayService) {} + constructor(private readonly pDSPAInitializePathwayService: PDSPA_InitializePathwayService) {} @Post('init') @ApiCreatedResponse({ diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts index 354da6c9..750c3e0d 100644 --- a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts @@ -1,15 +1,15 @@ import { PDSPAIUInitializePathwayUsecase, PDSPAInitializePathwayCommandHandler, - PDSPAInitializePathwayService, + PDSPA_InitializePathwayService, } from '@bewoak/pathway-design-server-pathway-application'; import { type DynamicModule, Module, type Type } from '@nestjs/common'; import { InitializePathwayController } from './controller/initialize-pathway.controller'; @Module({ controllers: [InitializePathwayController], - providers: [PDSPAInitializePathwayCommandHandler, PDSPAInitializePathwayService, PDSPAIUInitializePathwayUsecase], - exports: [PDSPAInitializePathwayService], + providers: [PDSPAInitializePathwayCommandHandler, PDSPA_InitializePathwayService, PDSPAIUInitializePathwayUsecase], + exports: [PDSPA_InitializePathwayService], }) // biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module export class PDSPIAInitializePathwayInterfaceAdaptersModule { diff --git a/libs/pathway-design/server/pathway/presenters/src/index.ts b/libs/pathway-design/server/pathway/presenters/src/index.ts index 579de838..519090a3 100644 --- a/libs/pathway-design/server/pathway/presenters/src/index.ts +++ b/libs/pathway-design/server/pathway/presenters/src/index.ts @@ -1,5 +1,3 @@ -export { - PDSPPPathwayPresentersModule, - PDSPPPresenterDriverAuthorized, - pDSPPPresenterKeys, -} from './lib/pathway-presenters.module'; +export { pDSPPPresenterKeys } from './lib/pathway-presenters.constants'; +export { PDSPPPathwayPresentersModule } from './lib/pathway-presenters.module'; +export { PDSPPPresenterDriverAuthorized } from './lib/pathway-presenters.types'; diff --git a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts new file mode 100644 index 00000000..34549a6e --- /dev/null +++ b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts @@ -0,0 +1,8 @@ +import type { PDSPPPresenterDriverAuthorized } from './pathway-presenters.types'; +import { ToJsonPathwayPresenterModule } from './toJson/to-json-pathway-presenter.module'; + +export const presenterModuleMap: Record = { + toJson: ToJsonPathwayPresenterModule, +}; + +export const pDSPPPresenterKeys = Object.keys(presenterModuleMap) as [PDSPPPresenterDriverAuthorized]; diff --git a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts index 41f4b058..b6a797eb 100644 --- a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts +++ b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts @@ -1,13 +1,6 @@ import { Module } from '@nestjs/common'; -import { ToJsonPathwayPresenterModule } from './toJson/to-json-pathway-presenter.module'; - -const presenterModuleMap: Record<'toJson', typeof ToJsonPathwayPresenterModule> = { - toJson: ToJsonPathwayPresenterModule, -}; - -export const pDSPPPresenterKeys = Object.keys(presenterModuleMap) as [PDSPPPresenterDriverAuthorized]; - -export type PDSPPPresenterDriverAuthorized = keyof typeof presenterModuleMap; +import { presenterModuleMap } from './pathway-presenters.constants'; +import type { PDSPPPresenterDriverAuthorized } from './pathway-presenters.types'; @Module({}) // biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module diff --git a/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts new file mode 100644 index 00000000..3b60492c --- /dev/null +++ b/libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts @@ -0,0 +1 @@ +export type PDSPPPresenterDriverAuthorized = 'toJson';