diff --git a/.detective/hash b/.detective/hash index b610274e..b5ad6d4b 100644 --- a/.detective/hash +++ b/.detective/hash @@ -1 +1 @@ -642b80d2d427239e1c6fdcd349f22edd0f79d0e6, v1.1.6 \ No newline at end of file +7293506443296ea9cf3b4c4f9160806365be91e2, v1.1.6 \ No newline at end of file diff --git a/.detective/log b/.detective/log index 86e86b89..019ad0fd 100644 --- a/.detective/log +++ b/.detective/log @@ -1,3 +1,138 @@ +"Mathieu Collette ,Thu Oct 17 12:05:45 2024 +0200 fd282696dc8ac4c83007497b5bfdfaee134e728b,refactor: extract business rules" +4 1 libs/pathway-design/common/business/pathway/rules/src/index.ts +19 0 libs/pathway-design/common/business/pathway/rules/src/lib/description/description.rules.ts +52 0 libs/pathway-design/common/business/pathway/rules/src/lib/description/description.spec.ts +10 0 libs/pathway-design/common/business/pathway/rules/src/lib/pathway-id/pathway-id.rules.ts +22 0 libs/pathway-design/common/business/pathway/rules/src/lib/pathway-id/pathway-id.spec.ts +19 0 libs/pathway-design/common/business/pathway/rules/src/lib/research-field/research-field.rules.ts +52 0 libs/pathway-design/common/business/pathway/rules/src/lib/research-field/research-field.spec.ts +13 6 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts +26 12 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.spec.ts +4 3 libs/pathway-design/common/business/pathway/rules/src/lib/types.ts +0 44 libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.spec.ts +2 2 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature +4 3 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts +4 47 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature +4 3 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts +3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.spec.ts +3 6 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.ts +3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.spec.ts +3 8 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts +3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.spec.ts +3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.ts +3 2 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.spec.ts +3 3 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.ts + +"Mathieu Collette ,Mon Oct 14 18:42:15 2024 +0200 84773010de01b55d429b7696c29c3056e9aaa362,fix: business rules" +4 4 libs/pathway-design/common/business/pathway/rules/project.json +2 2 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts + +"Mathieu Collette ,Mon Oct 14 18:30:13 2024 +0200 c12202b6e7f740b6a3fdf59c61b4b05f22531e92,refactor: pathway rules" +22 0 libs/pathway-design/common/business/pathway/rules/.swcrc +17 0 libs/pathway-design/common/business/pathway/rules/biome.json +11 0 libs/pathway-design/common/business/pathway/rules/cucumber.js +9 0 libs/pathway-design/common/business/pathway/rules/package.json +50 0 libs/pathway-design/common/business/pathway/rules/project.json +1 0 libs/pathway-design/common/business/pathway/rules/src/index.ts +12 0 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.rules.ts +38 0 libs/pathway-design/common/business/pathway/rules/src/lib/title/title.spec.ts +6 0 libs/pathway-design/common/business/pathway/rules/src/lib/types.ts +22 0 libs/pathway-design/common/business/pathway/rules/tsconfig.json +11 0 libs/pathway-design/common/business/pathway/rules/tsconfig.lib.json +10 0 libs/pathway-design/common/business/pathway/rules/tsconfig.spec.json +1 1 libs/pathway-design/server/pathway/application/src/index.ts +1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts +1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/description.value-object.ts +1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/pathway-id.value-object.ts +1 1 libs/pathway-design/server/pathway/business/src/lib/value-objects/research-field.value-object.ts +3 6 libs/pathway-design/server/pathway/business/src/lib/value-objects/title.value-object.ts +2 2 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts +3 3 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts +0 0 libs/{pathway-design/server/common/.keep => search/client/.gitkeep} +0 0 libs/search/{.keep => server/pathway/.gitkeep} +3 0 tsconfig.base.json + +"Mathieu Collette ,Fri Oct 11 21:06:03 2024 +0200 a94f94a17feedff2481a42013c43c3eb097790d6,refactor: env variables" +1 1 libs/pathway-design/server/pathway/application/src/index.ts +1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/service/initialize-pathway.service.ts +3 5 libs/pathway-design/server/pathway/infrastructure/src/index.ts +28 0 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.constants.ts +3 24 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts +1 0 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.types.ts +2 2 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/controller/initialize-pathway.controller.ts +3 3 libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/initialize-pathway-interface-adapters.module.ts +3 5 libs/pathway-design/server/pathway/presenters/src/index.ts +8 0 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.constants.ts +2 9 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts +1 0 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.types.ts + +"Mathieu Collette ,Fri Oct 11 18:10:50 2024 +0200 20f4ced81196ef5adf8ccfbfdcba870df16422cc,feat: choice presenter persistence" +36 17 apps/pathway-design/server/src/app/app.module.ts +10 0 apps/pathway-design/server/src/environment/env.schema.ts +27 30 apps/pathway-design/server/src/main.ts +6 3 apps/pathway-design/server/src/specs/change-title-pathway/index.feature +17 11 apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts +6 4 apps/pathway-design/server/src/specs/initialize-pathway/index.feature +14 8 apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts +3 0 biome.json +- - bun.lockb +22 0 libs/common/configs/server/env/.swcrc +17 0 libs/common/configs/server/env/biome.json +11 0 libs/common/configs/server/env/cucumber.js +9 0 libs/common/configs/server/env/package.json +50 0 libs/common/configs/server/env/project.json +2 0 libs/common/configs/server/env/src/index.ts +15 0 libs/common/configs/server/env/src/lib/check-env-variables.ts +4 0 libs/common/configs/server/env/src/lib/get-env-variables.ts +22 0 libs/common/configs/server/env/tsconfig.json +11 0 libs/common/configs/server/env/tsconfig.lib.json +10 0 libs/common/configs/server/env/tsconfig.spec.json +22 0 libs/common/configs/server/swagger/.swcrc +17 0 libs/common/configs/server/swagger/biome.json +11 0 libs/common/configs/server/swagger/cucumber.js +9 0 libs/common/configs/server/swagger/package.json +50 0 libs/common/configs/server/swagger/project.json +1 0 libs/common/configs/server/swagger/src/index.ts +30 0 libs/common/configs/server/swagger/src/lib/swagger.config.ts +7 0 libs/common/configs/server/swagger/src/lib/types.ts +22 0 libs/common/configs/server/swagger/tsconfig.json +11 0 libs/common/configs/server/swagger/tsconfig.lib.json +10 0 libs/common/configs/server/swagger/tsconfig.spec.json +1 1 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts +11 3 libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts +9 3 libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts +1 1 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts +11 2 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts +5 1 libs/pathway-design/server/pathway/infrastructure/src/index.ts +4 2 libs/pathway-design/server/pathway/infrastructure/src/lib/persistence/pathway-persistence-infrastructure.module.ts +5 1 libs/pathway-design/server/pathway/presenters/src/index.ts +4 2 libs/pathway-design/server/pathway/presenters/src/lib/pathway-presenters.module.ts +3 2 package.json +2 0 tsconfig.base.json + +"Mathieu Collette ,Wed Oct 9 19:02:42 2024 +0200 bf2d801496fa76753b3d70350c4ab3a5b8efe71c,refactor: formatting" +8 26 .detective/config.json + +"Mathieu Collette ,Wed Oct 9 19:02:07 2024 +0200 6313b5bc062895cfb152c14a3b1d880c2369a8eb,refactor: feature tests" +25 50 .detective/config.json +1 1 .detective/hash +225 417 .detective/log +3 0 .gitignore +5 5 apps/pathway-design/server/src/specs/change-title-pathway/index.feature +6 6 apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts +5 5 apps/pathway-design/server/src/specs/initialize-pathway/index.feature +6 6 apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts +- - bun.lockb +2 2 libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.feature +10 10 libs/pathway-design/server/pathway/application/src/lib/change-title/specs/change-title-pathway.usecase.step.ts +2 2 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.feature +10 10 libs/pathway-design/server/pathway/application/src/lib/initialize/specs/initialize-pathway.usecase.step.ts +8 8 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.feature +5 5 libs/pathway-design/server/pathway/business/src/lib/specs/change-name/change-title-pathway.step.ts +31 31 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.feature +4 4 libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts +4 2 package.json + "Mathieu Collette ,Sat Sep 14 15:29:45 2024 +0200 3e4a5edcc2aa4cee558971e8876d01ad672d91a0,feat: implement change title" 1 1 .hooks/commit-msg 2 2 apps/pathway-design/server/cucumber.js diff --git a/apps/pathway-design/client/.gitkeep b/apps/pathway-design/client/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/apps/pathway-design/server/src/app/app.module.ts b/apps/pathway-design/server/src/app/app.module.ts index ee3fb2dd..2c91738f 100644 --- a/apps/pathway-design/server/src/app/app.module.ts +++ b/apps/pathway-design/server/src/app/app.module.ts @@ -13,6 +13,7 @@ import { type PDSPPPresenterDriverAuthorized, } from '@bewoak/pathway-design-server-pathway-presenters'; import { CqrsModule } from '@nestjs/cqrs'; +import { EventEmitterModule } from '@nestjs/event-emitter'; interface ApplicationBootstrapOptions { persistenceDriver: PDSPIPPersistenceDriverAuthorized; @@ -37,7 +38,15 @@ export class AppModule { .withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(options.persistenceDriver)) .build(), CqrsModule.forRoot(), - CqrsModule.forRoot(), + EventEmitterModule.forRoot({ + wildcard: false, + delimiter: '.', + newListener: false, + removeListener: false, + maxListeners: 10, + verboseMemoryLeak: true, + ignoreErrors: false, + }), ], }; } diff --git a/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts b/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts index a9e96333..e6eb03be 100644 --- a/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts +++ b/apps/pathway-design/server/src/specs/change-title-pathway/index.step.ts @@ -15,6 +15,7 @@ import { import type { DataTable } from '@cucumber/cucumber'; import type { INestApplication } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; +import { EventEmitterModule } from '@nestjs/event-emitter'; import { Test } from '@nestjs/testing'; import { binding, given, then, when } from 'cucumber-tsflow'; import request from 'supertest'; @@ -36,6 +37,15 @@ class ControllerSteps { .withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence)) .build(), CqrsModule.forRoot(), + EventEmitterModule.forRoot({ + wildcard: false, + delimiter: '.', + newListener: false, + removeListener: false, + maxListeners: 10, + verboseMemoryLeak: true, + ignoreErrors: false, + }), ], }).compile(); diff --git a/apps/pathway-design/server/src/specs/initialize-pathway/index.feature b/apps/pathway-design/server/src/specs/initialize-pathway/index.feature index 71d8a19d..9afeb855 100644 --- a/apps/pathway-design/server/src/specs/initialize-pathway/index.feature +++ b/apps/pathway-design/server/src/specs/initialize-pathway/index.feature @@ -8,6 +8,7 @@ Feature: Platform - Initialize a Pathway Then I should retrieve from the platform a pathway initialized with its data | title | description | researchField | | My Pathway | A test pathway | biology | + Then The platform should send an event to the event bus with the pathway initialized Then The pathway received from the platform should be have a unique identifier Examples: diff --git a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts index 84f88bef..f81a7692 100644 --- a/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts +++ b/apps/pathway-design/server/src/specs/initialize-pathway/index.step.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; import type { Http2Server } from 'node:http2'; +import { CCEPPathwayInitializedEvent } from '@bewoak/common-contracts-events-pathway'; import { PDSPIPPathwayPersistenceInfrastructureModule, type PDSPIPPersistenceDriverAuthorized, @@ -12,13 +13,17 @@ import { import type { DataTable } from '@cucumber/cucumber'; import type { INestApplication } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; +import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter'; import { Test } from '@nestjs/testing'; import { binding, given, then, when } from 'cucumber-tsflow'; +import sinon from 'sinon'; import request from 'supertest'; @binding() class ControllerSteps { private app: INestApplication; + private eventEmitter: EventEmitter2; + private eventEmitterSpy: sinon.SinonSpy | undefined; private httpServer: Http2Server; private response: request.Response; @@ -30,12 +35,25 @@ class ControllerSteps { .withPersistence(PDSPIPPathwayPersistenceInfrastructureModule.use(persistence)) .build(), CqrsModule.forRoot(), + EventEmitterModule.forRoot({ + wildcard: false, + delimiter: '.', + newListener: false, + removeListener: false, + maxListeners: 10, + verboseMemoryLeak: true, + ignoreErrors: false, + }), ], exports: [], }).compile(); this.app = testingModule.createNestApplication(); await this.app.init(); + + this.eventEmitter = this.app.get(EventEmitter2); + this.eventEmitterSpy = sinon.spy(this.eventEmitter, 'emit'); + this.httpServer = this.app.getHttpServer(); } @@ -50,6 +68,23 @@ class ControllerSteps { }); } + @then('The platform should send an event to the event bus with the pathway initialized') + public thenPlatformSendAnEventToEventBus() { + const expectedEvent = new CCEPPathwayInitializedEvent( + this.response.body.description, + this.response.body.id, + this.response.body.researchField, + this.response.body.title + ); + + const typeArg = this.eventEmitterSpy?.getCall(0).args[0]; + const eventArgs = this.eventEmitterSpy?.getCall(0).args[1]; + + assert(this.eventEmitterSpy?.calledOnce); + assert.deepStrictEqual(typeArg, expectedEvent.eventType); + assert.deepStrictEqual(eventArgs, expectedEvent); + } + @then('I should retrieve from the platform a pathway initialized with its data') public thenIShouldRetrieveAPathwayInitiated(dataTable: DataTable) { const firstRow = dataTable.hashes()[0]; diff --git a/bun.lockb b/bun.lockb index 0b6e79cc..4055572c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/libs/common/contracts/events/pathway/.swcrc b/libs/common/contracts/events/pathway/.swcrc new file mode 100644 index 00000000..d24f1ace --- /dev/null +++ b/libs/common/contracts/events/pathway/.swcrc @@ -0,0 +1,22 @@ +{ + "jsc": { + "target": "es2022", + "parser": { + "syntax": "typescript", + "decorators": true, + "dynamicImport": true + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true + }, + "keepClassNames": true, + "externalHelpers": true, + "loose": true + }, + "module": { + "type": "es6" + }, + "sourceMaps": true, + "exclude": [".*\\.spec.tsx?$", ".*\\.step.ts$", ".*\\.test.tsx?$", ".*.js$"] +} diff --git a/libs/common/contracts/events/pathway/biome.json b/libs/common/contracts/events/pathway/biome.json new file mode 100644 index 00000000..7a38d8eb --- /dev/null +++ b/libs/common/contracts/events/pathway/biome.json @@ -0,0 +1,17 @@ +{ + "$schema": "../../../../../node_modules/@biomejs/biome/configuration_schema.json", + "extends": ["../../../../../biome.json"], + "linter": { + "rules": { + "nursery": { + "noRestrictedImports": { + "options": { + "paths": {} + }, + "level": "error" + } + } + } + }, + "overrides": [{}] +} diff --git a/libs/common/contracts/events/pathway/cucumber.js b/libs/common/contracts/events/pathway/cucumber.js new file mode 100644 index 00000000..4825e151 --- /dev/null +++ b/libs/common/contracts/events/pathway/cucumber.js @@ -0,0 +1,11 @@ +module.exports = { + default: { + paths: ['libs/common/contracts/events/pathway/src/lib/**/*.feature'], + requireModule: ['ts-node/register', 'tsconfig-paths/register'], + require: ['libs/common/contracts/events/pathway/src/lib/**/*.step.ts'], + format: [ + 'json:dist/reports/libs/common/contracts/events/pathway/test-feature/index.json', + 'html:dist/reports/libs/common/contracts/events/pathway/test-feature/index.html', + ], + }, +}; diff --git a/libs/common/contracts/events/pathway/package.json b/libs/common/contracts/events/pathway/package.json new file mode 100644 index 00000000..51716e28 --- /dev/null +++ b/libs/common/contracts/events/pathway/package.json @@ -0,0 +1,9 @@ +{ + "name": "@bewoak/common-contracts-events-pathway", + "version": "0.0.1", + "dependencies": { + "@swc/helpers": "~0.5.11" + }, + "main": "./src/index.js", + "typings": "./src/index.d.ts" +} diff --git a/libs/common/contracts/events/pathway/project.json b/libs/common/contracts/events/pathway/project.json new file mode 100644 index 00000000..768608f5 --- /dev/null +++ b/libs/common/contracts/events/pathway/project.json @@ -0,0 +1,50 @@ +{ + "name": "common-contracts-events-pathway", + "$schema": "../../../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/common/contracts/events/pathway/src", + "projectType": "library", + "targets": { + "build": { + "executor": "@nx/js:swc", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/common/contracts/events/pathway", + "main": "libs/common/contracts/events/pathway/src/index.ts", + "tsConfig": "libs/common/contracts/events/pathway/tsconfig.lib.json", + "assets": [] + } + }, + "nx-release-publish": { + "options": { + "packageRoot": "dist/{projectRoot}" + } + }, + "lint": { + "executor": "nx:run-commands", + "options": { + "command": "bun run biome check --write {projectRoot} --config-path={projectRoot}/biome.json" + } + }, + "test": { + "executor": "nx:run-commands", + "options": { + "command": "bun test --coverage --coverage-dir=dist/reports/{projectRoot}/coverage --coverage-reporter=lcov {projectRoot}" + } + }, + "test-feature": { + "executor": "nx:run-commands", + "options": { + "command": "TS_NODE_PROJECT='{projectRoot}/tsconfig.spec.json' bun run cucumber-js --config={projectRoot}/cucumber.js" + } + } + }, + "tags": ["type:common:configs:server:swagger"], + "release": { + "version": { + "generatorOptions": { + "packageRoot": "dist/{projectRoot}", + "currentVersionResolver": "git-tag" + } + } + } +} diff --git a/libs/common/contracts/events/pathway/src/index.ts b/libs/common/contracts/events/pathway/src/index.ts new file mode 100644 index 00000000..b114e765 --- /dev/null +++ b/libs/common/contracts/events/pathway/src/index.ts @@ -0,0 +1 @@ +export { CCEPPathwayInitializedEvent } from './lib/initialized/pathway-initialized.event'; diff --git a/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.constants.ts b/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.constants.ts new file mode 100644 index 00000000..69fdac75 --- /dev/null +++ b/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.constants.ts @@ -0,0 +1 @@ +export const CCEP_EVENT_TYPE_PATHWAY_INITIALIZED = 'PathwayInitialized' as const; diff --git a/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.event.ts b/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.event.ts new file mode 100644 index 00000000..d2e9d88c --- /dev/null +++ b/libs/common/contracts/events/pathway/src/lib/initialized/pathway-initialized.event.ts @@ -0,0 +1,12 @@ +import { CCEP_EVENT_TYPE_PATHWAY_INITIALIZED } from './pathway-initialized.constants'; + +export class CCEPPathwayInitializedEvent { + public readonly eventType = CCEP_EVENT_TYPE_PATHWAY_INITIALIZED; + + constructor( + public readonly description: string, + public readonly pathwayId: string, + public readonly researchField: string, + public readonly title: string + ) {} +} diff --git a/libs/common/contracts/events/pathway/tsconfig.json b/libs/common/contracts/events/pathway/tsconfig.json new file mode 100644 index 00000000..679400da --- /dev/null +++ b/libs/common/contracts/events/pathway/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "../../../../../tsconfig.base.json", + "compilerOptions": { + "module": "es2022", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/common/contracts/events/pathway/tsconfig.lib.json b/libs/common/contracts/events/pathway/tsconfig.lib.json new file mode 100644 index 00000000..5c40769b --- /dev/null +++ b/libs/common/contracts/events/pathway/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../../../dist/out-tsc", + "types": ["node"], + "composite": true, + "declaration": true + }, + "include": ["src/**/*.ts"], + "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.step.ts"] +} diff --git a/libs/common/contracts/events/pathway/tsconfig.spec.json b/libs/common/contracts/events/pathway/tsconfig.spec.json new file mode 100644 index 00000000..a8c23a46 --- /dev/null +++ b/libs/common/contracts/events/pathway/tsconfig.spec.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "esModuleInterop": true, + "composite": true, + "declaration": true + }, + "include": ["src/**/*.ts"] +} diff --git a/libs/common/contracts/http/.gitkeep b/libs/common/contracts/http/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/libs/pathway-design/server/pathway/application/project.json b/libs/pathway-design/server/pathway/application/project.json index 7a226e23..d2329ae1 100644 --- a/libs/pathway-design/server/pathway/application/project.json +++ b/libs/pathway-design/server/pathway/application/project.json @@ -8,7 +8,7 @@ "executor": "@nx/js:swc", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/libs/pathway-design/server/pathway/business/usecases/init", + "outputPath": "dist/libs/pathway-design/server/pathway/application", "main": "libs/pathway-design/server/pathway/application/src/index.ts", "tsConfig": "libs/pathway-design/server/pathway/application/tsconfig.lib.json", "assets": [] diff --git a/libs/pathway-design/server/pathway/application/src/index.ts b/libs/pathway-design/server/pathway/application/src/index.ts index 5634ae43..726bddf8 100644 --- a/libs/pathway-design/server/pathway/application/src/index.ts +++ b/libs/pathway-design/server/pathway/application/src/index.ts @@ -7,3 +7,4 @@ export { PDSPAChangeTitlePathwayCommand } from './lib/change-title/command/chang export { PDSPAChangeTitlePathwayCommandHandler } from './lib/change-title/command/change-title-pathway.command-handler'; export { PDSPAChangeTitlePathwayService } from './lib/change-title/service/change-title-pathway.service'; export { PDSPACUChangeTitlePathwayUseCase } from './lib/change-title/usecase/change-title-pathway.usecase'; +export { PDSPAInitializePathwayEventHandler } from './lib/initialize/event-handler/initialize-pathway.event-handler'; diff --git a/libs/pathway-design/server/pathway/application/src/lib/initialize/event-handler/initialize-pathway.event-handler.ts b/libs/pathway-design/server/pathway/application/src/lib/initialize/event-handler/initialize-pathway.event-handler.ts new file mode 100644 index 00000000..f70a01e4 --- /dev/null +++ b/libs/pathway-design/server/pathway/application/src/lib/initialize/event-handler/initialize-pathway.event-handler.ts @@ -0,0 +1,20 @@ +import { CCEPPathwayInitializedEvent } from '@bewoak/common-contracts-events-pathway'; +import { PDSPBEPathwayInitializedEvent } from '@bewoak/pathway-design-server-pathway-business'; +import { EventsHandler, type IEventHandler } from '@nestjs/cqrs'; +// biome-ignore lint/style/useImportType: +import { EventEmitter2 } from '@nestjs/event-emitter'; + +@EventsHandler(PDSPBEPathwayInitializedEvent) +export class PDSPAInitializePathwayEventHandler implements IEventHandler { + constructor(private readonly eventEmitter: EventEmitter2) {} + + handle(pDSPBEPathwayInitializedEvent: PDSPBEPathwayInitializedEvent) { + const event = new CCEPPathwayInitializedEvent( + pDSPBEPathwayInitializedEvent.payload.description, + pDSPBEPathwayInitializedEvent.payload.pathwayId, + pDSPBEPathwayInitializedEvent.payload.researchField, + pDSPBEPathwayInitializedEvent.payload.title + ); + this.eventEmitter.emit(event.eventType, event); + } +} 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..09cb0be8 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 @@ -8,7 +8,7 @@ import type { PDSPAInitializePathwayCommand } from '../command/initialize-pathwa export class PDSPAInitializePathwayService { constructor(private readonly commandBus: CommandBus) {} - init(pDSPAInitializePathwayCommand: PDSPAInitializePathwayCommand) { + initialize(pDSPAInitializePathwayCommand: PDSPAInitializePathwayCommand) { return this.commandBus.execute(pDSPAInitializePathwayCommand); } } diff --git a/libs/pathway-design/server/pathway/business/src/index.ts b/libs/pathway-design/server/pathway/business/src/index.ts index 50cce7fd..65793914 100644 --- a/libs/pathway-design/server/pathway/business/src/index.ts +++ b/libs/pathway-design/server/pathway/business/src/index.ts @@ -1,4 +1,5 @@ export { PDSPBEPathwayEntity } from './lib/entities/pathway'; +export { PDSPBEPathwayInitializedEvent } from './lib/events/pathway-initialized.event'; export { pDSPBFPathwayFactory } from './lib/factories/pathway.factory'; export { PDSPBP_CHANGE_TITLE_PATHWAY_PERSISTENCE_PORT, diff --git a/libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts b/libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts index 22ac5020..8c27378e 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/entities/pathway.ts @@ -29,7 +29,7 @@ export class PDSPBEPathwayEntity extends AggregateRoot { return this.#title?.value ?? ''; } - init({ id, title, description, researchField }: InitializePathwayParams) { + initialize({ id, title, description, researchField }: InitializePathwayParams) { this.#description = description; this.#id = id; this.#researchField = researchField; @@ -37,10 +37,10 @@ export class PDSPBEPathwayEntity extends AggregateRoot { this.apply( new PDSPBEPathwayInitializedEvent(this.id, { - pathwayId: this.id, - title: this.title, description: this.description, + pathwayId: this.id, researchField: this.researchField, + title: this.title, }), { skipHandler: true, diff --git a/libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts b/libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts index 40e20313..638e9a46 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/events/pathway-initialized.event.ts @@ -6,6 +6,11 @@ export class PDSPBEPathwayInitializedEvent implements CEEvent { constructor( public readonly aggregateId: string, - public readonly payload: Record + public readonly payload: { + description: string; + pathwayId: string; + researchField: string; + title: string; + } ) {} } diff --git a/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.ts b/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.ts index c7fd9d57..6aeccf5b 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/factories/pathway.factory.ts @@ -20,7 +20,7 @@ export const pDSPBFPathwayFactory = ({ const uuid = idValue ?? randomUUID(); const id = new PathwayIdValueObject(uuid); - pathway.init({ + pathway.initialize({ id, title, description, diff --git a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts index fc2eca48..d4a51bd0 100644 --- a/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts +++ b/libs/pathway-design/server/pathway/business/src/lib/specs/initialize/initialize-pathway.step.ts @@ -30,7 +30,7 @@ export default class PathwaySteps { const researchField = new ResearchFieldValueObjects(data.researchField); this.pDSPBEPathwayEntity = new PDSPBEPathwayEntity(); - this.pDSPBEPathwayEntity.init({ + this.pDSPBEPathwayEntity.initialize({ id, title, description, @@ -56,7 +56,7 @@ export default class PathwaySteps { this.pDSPBEPathwayEntity = new PDSPBEPathwayEntity(); this.applyMethodSpy = sinon.spy(this.pDSPBEPathwayEntity, 'apply'); - this.pDSPBEPathwayEntity.init({ + this.pDSPBEPathwayEntity.initialize({ id, title, description, 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..e5863b57 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 @@ -31,7 +31,7 @@ export class InitializePathwayController { execute( @Body() initializePathwayRequestBodyDto: InitializePathwayRequestBodyDto ): Promise { - return this.pDSPAInitializePathwayService.init( + return this.pDSPAInitializePathwayService.initialize( new PDSPAInitializePathwayCommand( initializePathwayRequestBodyDto.description, initializePathwayRequestBodyDto.researchField, 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..4f45b0fe 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,6 +1,7 @@ import { PDSPAIUInitializePathwayUsecase, PDSPAInitializePathwayCommandHandler, + PDSPAInitializePathwayEventHandler, PDSPAInitializePathwayService, } from '@bewoak/pathway-design-server-pathway-application'; import { type DynamicModule, Module, type Type } from '@nestjs/common'; @@ -8,7 +9,12 @@ import { InitializePathwayController } from './controller/initialize-pathway.con @Module({ controllers: [InitializePathwayController], - providers: [PDSPAInitializePathwayCommandHandler, PDSPAInitializePathwayService, PDSPAIUInitializePathwayUsecase], + providers: [ + PDSPAIUInitializePathwayUsecase, + PDSPAInitializePathwayCommandHandler, + PDSPAInitializePathwayEventHandler, + PDSPAInitializePathwayService, + ], exports: [PDSPAInitializePathwayService], }) // biome-ignore lint/complexity/noStaticOnlyClass: not pertinent here because this is a module diff --git a/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/routes/initialize-pathway.route.ts b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/routes/initialize-pathway.route.ts new file mode 100644 index 00000000..575cca38 --- /dev/null +++ b/libs/pathway-design/server/pathway/interface-adapters/src/lib/initialize/routes/initialize-pathway.route.ts @@ -0,0 +1,4 @@ +export const pDSPIAPathwayPathSuffix = 'pathway'; +export const pDSPIAPathwayTag = 'Pathway'; +export const pDSPIAPathwayPath = `${pDSPIAPathwayPathSuffix}`; +export const pDSPIAInitializePathwayPath = 'initialize'; diff --git a/package.json b/package.json index 4c8a93d8..5f7428f9 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "@nestjs/common": "^10.0.2", "@nestjs/core": "^10.0.2", "@nestjs/cqrs": "^10.2.7", + "@nestjs/event-emitter": "^2.0.4", "@nestjs/platform-express": "^10.0.2", "@nestjs/swagger": "^7.4.0", "@swc/cli": "^0.4.0", diff --git a/tsconfig.base.json b/tsconfig.base.json index cb5f8356..edc6bb14 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -12,6 +12,7 @@ "paths": { "@bewoak/common-configs-server-env": ["libs/common/configs/server/env/src/index.ts"], "@bewoak/common-configs-server-swagger": ["libs/common/configs/server/swagger/src/index.ts"], + "@bewoak/common-contracts-events-pathway": ["libs/common/contracts/events/pathway/src/index.ts"], "@bewoak/common-events": ["libs/common/events/src/index.ts"], "@bewoak/common-tools-server-http-exceptions": ["libs/common/tools/server/http-exceptions/src/index.ts"], "@bewoak/pathway-design-common-business-pathway-rules": [