From 35efcd62ffcf445cd92c6c66fab2acfbccccb8bf Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 19 Mar 2026 14:39:35 -0700 Subject: [PATCH] add a reconstitute method to connection domain object to avoid create event --- src/modules/cards/domain/Connection.ts | 18 ++++++++++++++++++ .../repositories/mappers/ConnectionMapper.ts | 4 ++-- .../utils/InMemoryConnectionRepository.ts | 4 +++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/modules/cards/domain/Connection.ts b/src/modules/cards/domain/Connection.ts index 896f5770..671e6289 100644 --- a/src/modules/cards/domain/Connection.ts +++ b/src/modules/cards/domain/Connection.ts @@ -112,6 +112,24 @@ export class Connection extends AggregateRoot { return ok(connection); } + public static reconstitute( + props: ConnectionProps, + id: UniqueEntityID, + ): Result { + // Validate that source and target are not the same + if (props.source.equals(props.target)) { + return err( + new ConnectionValidationError( + 'Connection source and target cannot be the same', + ), + ); + } + + // Note: No event raising for reconstituted connections + const connection = new Connection(props, id); + return ok(connection); + } + public updateNote( note: ConnectionNote, ): Result { diff --git a/src/modules/cards/infrastructure/repositories/mappers/ConnectionMapper.ts b/src/modules/cards/infrastructure/repositories/mappers/ConnectionMapper.ts index b0402b00..1742b143 100644 --- a/src/modules/cards/infrastructure/repositories/mappers/ConnectionMapper.ts +++ b/src/modules/cards/infrastructure/repositories/mappers/ConnectionMapper.ts @@ -129,8 +129,8 @@ export class ConnectionMapper { } } - // Create the connection - const connectionOrError = Connection.create( + // Reconstitute the connection from the database (doesn't raise events) + const connectionOrError = Connection.reconstitute( { source: sourceOrError.value, target: targetOrError.value, diff --git a/src/modules/cards/tests/utils/InMemoryConnectionRepository.ts b/src/modules/cards/tests/utils/InMemoryConnectionRepository.ts index a59269cc..10b0b8b2 100644 --- a/src/modules/cards/tests/utils/InMemoryConnectionRepository.ts +++ b/src/modules/cards/tests/utils/InMemoryConnectionRepository.ts @@ -20,11 +20,13 @@ export class InMemoryConnectionRepository implements IConnectionRepository { } private clone(connection: Connection): Connection { - const connectionResult = Connection.create( + const connectionResult = Connection.reconstitute( { curatorId: connection.curatorId, source: connection.source, target: connection.target, + sourceUrlMetadata: connection.sourceUrlMetadata, + targetUrlMetadata: connection.targetUrlMetadata, type: connection.type, note: connection.note, publishedRecordId: connection.publishedRecordId, -- knotmirror 0.0.1