From f63ff660f0cd6b6feb4fa4e9dd1ef37582a87d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Fri, 18 Oct 2024 15:40:49 +0200 Subject: [PATCH 1/7] refactor: remove template from relationship in transport --- .../RelationshipTemplateController.ts | 5 +-- .../relationships/RelationshipsController.ts | 12 ++---- .../relationships/local/CachedRelationship.ts | 16 ++++++-- .../relationships/local/Relationship.ts | 7 ++-- .../transport/test/end2end/End2End.test.ts | 39 +------------------ .../RelationshipTemplateController.test.ts | 2 +- .../RelationshipsController.test.ts | 4 +- .../relationships/decomposition.test.ts | 2 +- 8 files changed, 25 insertions(+), 62 deletions(-) diff --git a/packages/transport/src/modules/relationshipTemplates/RelationshipTemplateController.ts b/packages/transport/src/modules/relationshipTemplates/RelationshipTemplateController.ts index d4476e086..c0764f318 100644 --- a/packages/transport/src/modules/relationshipTemplates/RelationshipTemplateController.ts +++ b/packages/transport/src/modules/relationshipTemplates/RelationshipTemplateController.ts @@ -263,9 +263,8 @@ export class RelationshipTemplateController extends TransportController { } public async cleanupTemplatesOfDecomposedRelationship(relationship: Relationship): Promise { - const templateOfRelationship = relationship.cache!.template; - - if (!templateOfRelationship.isOwn || templateOfRelationship.cache!.maxNumberOfAllocations === 1) { + const templateOfRelationship = await this.getRelationshipTemplate(relationship.cache!.templateId); + if (templateOfRelationship && (!templateOfRelationship.isOwn || templateOfRelationship.cache!.maxNumberOfAllocations === 1)) { await this.templates.delete(templateOfRelationship); } diff --git a/packages/transport/src/modules/relationships/RelationshipsController.ts b/packages/transport/src/modules/relationships/RelationshipsController.ts index 5fe507c59..86c0f0bc7 100644 --- a/packages/transport/src/modules/relationships/RelationshipsController.ts +++ b/packages/transport/src/modules/relationships/RelationshipsController.ts @@ -191,7 +191,7 @@ export class RelationshipsController extends TransportController { const backboneResponse = result.value; - const newRelationship = Relationship.fromBackboneAndCreationContent(backboneResponse, template, template.cache.identity, parameters.creationContent, secretId); + const newRelationship = Relationship.fromBackboneAndCreationContent(backboneResponse, template.cache.identity, parameters.creationContent, secretId); await this.relationships.create(newRelationship); @@ -369,19 +369,13 @@ export class RelationshipsController extends TransportController { const templateId = CoreId.from(response.relationshipTemplateId); - this._log.trace(`Parsing relationship template ${templateId} for ${response.id}...`); - const template = await this.parent.relationshipTemplates.getRelationshipTemplate(templateId); - if (!template) { - throw TransportCoreErrors.general.recordNotFound(RelationshipTemplate, templateId.toString()); - } - this._log.trace(`Parsing relationship creation content of ${response.id}...`); const creationContent = await this.decryptCreationContent(response.creationContent, CoreAddress.from(response.from), relationshipSecretId); const cachedRelationship = CachedRelationship.from({ creationContent: creationContent.content, - template, + templateId, auditLog: RelationshipAuditLog.fromBackboneAuditLog(response.auditLog) }); @@ -487,7 +481,7 @@ export class RelationshipsController extends TransportController { await this.secrets.createTemplatorSecrets(secretId, template.cache, creationContentCipher.publicCreationContentCrypto); const creationContent = await this.decryptCreationContent(backboneRelationship.creationContent, CoreAddress.from(backboneRelationship.from), secretId); - const relationship = Relationship.fromBackboneAndCreationContent(backboneRelationship, template, creationContent.identity, creationContent.content, secretId); + const relationship = Relationship.fromBackboneAndCreationContent(backboneRelationship, creationContent.identity, creationContent.content, secretId); await this.relationships.create(relationship); return relationship; diff --git a/packages/transport/src/modules/relationships/local/CachedRelationship.ts b/packages/transport/src/modules/relationships/local/CachedRelationship.ts index 26b81a5ca..9c6880c5c 100644 --- a/packages/transport/src/modules/relationships/local/CachedRelationship.ts +++ b/packages/transport/src/modules/relationships/local/CachedRelationship.ts @@ -1,10 +1,9 @@ import { ISerializable, Serializable, serialize, type, validate } from "@js-soft/ts-serval"; -import { CoreDate, ICoreDate } from "@nmshd/core-types"; -import { IRelationshipTemplate, RelationshipTemplate } from "../../relationshipTemplates/local/RelationshipTemplate"; +import { CoreDate, CoreId, ICoreDate, ICoreId } from "@nmshd/core-types"; import { IRelationshipAuditLogEntry, RelationshipAuditLogEntry } from "./RelationshipAuditLogEntry"; export interface ICachedRelationship extends ISerializable { - template: IRelationshipTemplate; + templateId: ICoreId; creationContent: ISerializable; lastMessageSentAt?: ICoreDate; @@ -16,7 +15,7 @@ export interface ICachedRelationship extends ISerializable { export class CachedRelationship extends Serializable implements ICachedRelationship { @validate() @serialize() - public template: RelationshipTemplate; + public templateId: CoreId; @validate() @serialize() @@ -34,6 +33,15 @@ export class CachedRelationship extends Serializable implements ICachedRelations @serialize({ type: RelationshipAuditLogEntry }) public auditLog: RelationshipAuditLogEntry[]; + public static override preFrom(value: any): any { + if (typeof value.template !== "undefined") { + value.templateId = value.template.id; + delete value.template; + } + + return value; + } + public static from(value: ICachedRelationship): CachedRelationship { return this.fromAny(value); } diff --git a/packages/transport/src/modules/relationships/local/Relationship.ts b/packages/transport/src/modules/relationships/local/Relationship.ts index c543abc6b..6ec1681f9 100644 --- a/packages/transport/src/modules/relationships/local/Relationship.ts +++ b/packages/transport/src/modules/relationships/local/Relationship.ts @@ -3,7 +3,6 @@ import { CoreDate, CoreId, ICoreId } from "@nmshd/core-types"; import { nameof } from "ts-simple-nameof"; import { CoreSynchronizable, ICoreSynchronizable, TransportError } from "../../../core"; import { Identity, IIdentity } from "../../accounts/data/Identity"; -import { IRelationshipTemplate } from "../../relationshipTemplates/local/RelationshipTemplate"; import { BackboneGetRelationshipResponse } from "../backbone/BackboneGetRelationships"; import { RelationshipStatus } from "../transmission/RelationshipStatus"; import { CachedRelationship, ICachedRelationship } from "./CachedRelationship"; @@ -74,23 +73,23 @@ export class Relationship extends CoreSynchronizable implements IRelationship { // Adds flattened peerAddress and templateId to the JSON stored in the database. // This helps us to boost the performance of database queries that include these fields. json.peerAddress = this.peer.address.toString(); - json.templateId = this.cache?.template.id.toString(); + json.templateId = this.cache?.templateId.toString(); return json; } public static fromBackboneAndCreationContent( response: BackboneGetRelationshipResponse, - template: IRelationshipTemplate, peer: IIdentity, creationContent: ISerializable, relationshipSecretId: CoreId ): Relationship { const cache = CachedRelationship.from({ creationContent, - template: template, + templateId: CoreId.from(response.relationshipTemplateId), auditLog: RelationshipAuditLog.fromBackboneAuditLog(response.auditLog) }); + return Relationship.from({ id: CoreId.from(response.id), relationshipSecretId: relationshipSecretId, diff --git a/packages/transport/test/end2end/End2End.test.ts b/packages/transport/test/end2end/End2End.test.ts index e0f61efd1..880021fa6 100644 --- a/packages/transport/test/end2end/End2End.test.ts +++ b/packages/transport/test/end2end/End2End.test.ts @@ -92,12 +92,6 @@ describe("RelationshipTest: Accept", function () { }); const relationshipId = request.id; - const templateRequestContent = request.cache!.template.cache!.content as JSONWrapper; - expect(templateRequestContent.value).toHaveProperty("mycontent"); - expect(templateRequestContent.value.mycontent).toBe("template"); - - expect(request.cache!.template.id.toString()).toStrictEqual(templateTo.id.toString()); - expect(request.cache!.template.isOwn).toBe(false); expect(request.status).toStrictEqual(RelationshipStatus.Pending); expect(request.cache?.auditLog).toHaveLength(1); @@ -107,13 +101,6 @@ describe("RelationshipTest: Accept", function () { expect(syncedRelationships).toHaveLength(1); const pendingRelationship = syncedRelationships[0]; - expect(pendingRelationship.cache!.template.id.toString()).toStrictEqual(templateTo.id.toString()); - expect(pendingRelationship.cache!.template.isOwn).toBe(true); - - const templateResponseContent = pendingRelationship.cache!.template.cache!.content as JSONWrapper; - expect(templateResponseContent.value).toHaveProperty("mycontent"); - expect(templateResponseContent.value.mycontent).toBe("template"); - expect(pendingRelationship.status).toStrictEqual(RelationshipStatus.Pending); const acceptedRelationshipFromSelf = await from.relationships.accept(relationshipId); @@ -206,23 +193,11 @@ describe("RelationshipTest: Reject", function () { }); const relationshipId = request.id; - const templateRequestContent = request.cache!.template.cache!.content as JSONWrapper; - expect(templateRequestContent.value).toHaveProperty("mycontent"); - expect(templateRequestContent.value.mycontent).toBe("template"); - - expect(request.cache!.template.id.toString()).toStrictEqual(templateTo.id.toString()); - expect(request.cache!.template.isOwn).toBe(false); expect(request.status).toStrictEqual(RelationshipStatus.Pending); const syncedRelationships = await TestUtil.syncUntilHasRelationships(from); expect(syncedRelationships).toHaveLength(1); const pendingRelationship = syncedRelationships[0]; - expect(pendingRelationship.cache!.template.id.toString()).toStrictEqual(templateTo.id.toString()); - expect(pendingRelationship.cache!.template.isOwn).toBe(true); - - const templateResponseContent = pendingRelationship.cache!.template.cache!.content as JSONWrapper; - expect(templateResponseContent.value).toHaveProperty("mycontent"); - expect(templateResponseContent.value.mycontent).toBe("template"); expect(pendingRelationship.status).toStrictEqual(RelationshipStatus.Pending); @@ -317,14 +292,8 @@ describe("RelationshipTest: Revoke", function () { } }); - const templateRequestContent = request.cache!.template.cache!.content as JSONWrapper; - expect(templateRequestContent.value).toHaveProperty("mycontent"); - expect(templateRequestContent.value.mycontent).toBe("template"); - const relationshipId = request.id; - expect(request.cache!.template.id.toString()).toStrictEqual(templateRequestor.id.toString()); - expect(request.cache!.template.isOwn).toBe(false); expect(request.status).toStrictEqual(RelationshipStatus.Pending); const syncedRelationships = await TestUtil.syncUntilHasRelationships(templator); @@ -332,12 +301,6 @@ describe("RelationshipTest: Revoke", function () { const pendingRelationship = syncedRelationships[0]; expect(pendingRelationship.status).toStrictEqual(RelationshipStatus.Pending); - expect(pendingRelationship.cache!.template.id.toString()).toStrictEqual(templateRequestor.id.toString()); - expect(pendingRelationship.cache!.template.isOwn).toBe(true); - - const templateResponseContent = pendingRelationship.cache!.template.cache!.content as JSONWrapper; - expect(templateResponseContent.value).toHaveProperty("mycontent"); - expect(templateResponseContent.value.mycontent).toBe("template"); expect(pendingRelationship.status).toStrictEqual(RelationshipStatus.Pending); const revokedRelationshipSelf = await requestor.relationships.revoke(relationshipId); @@ -348,7 +311,7 @@ describe("RelationshipTest: Revoke", function () { expect(revokedRelationshipSelf.cache?.auditLog).toHaveLength(2); expect(revokedRelationshipSelf.cache!.auditLog[1].newStatus).toBe(RelationshipStatus.Revoked); expect(revokedRelationshipSelf.peer).toBeDefined(); - expect(revokedRelationshipSelf.peer.address.toString()).toStrictEqual(revokedRelationshipSelf.cache!.template.cache?.identity.address.toString()); + expect(revokedRelationshipSelf.peer.address.toString()).toStrictEqual(revokedRelationshipSelf.cache!.auditLog[0].createdBy.toString()); const syncedRelationshipsPeer = await TestUtil.syncUntilHasRelationships(templator); expect(syncedRelationshipsPeer).toHaveLength(1); diff --git a/packages/transport/test/modules/relationshipTemplates/RelationshipTemplateController.test.ts b/packages/transport/test/modules/relationshipTemplates/RelationshipTemplateController.test.ts index 76833487e..d6c757347 100644 --- a/packages/transport/test/modules/relationshipTemplates/RelationshipTemplateController.test.ts +++ b/packages/transport/test/modules/relationshipTemplates/RelationshipTemplateController.test.ts @@ -165,7 +165,7 @@ describe("RelationshipTemplateController", function () { await sender.relationshipTemplates.cleanupTemplatesOfDecomposedRelationship(relationship); - const templateForRelationship = await sender.relationshipTemplates.getRelationshipTemplate(relationship.cache!.template.id); + const templateForRelationship = await sender.relationshipTemplates.getRelationshipTemplate(relationship.cache!.templateId); const otherTemplate = await sender.relationshipTemplates.getRelationshipTemplate(templateId); expect(templateForRelationship).toBeUndefined(); expect(otherTemplate).toBeUndefined(); diff --git a/packages/transport/test/modules/relationships/RelationshipsController.test.ts b/packages/transport/test/modules/relationships/RelationshipsController.test.ts index 819cdb0a2..cb18c0b77 100644 --- a/packages/transport/test/modules/relationships/RelationshipsController.test.ts +++ b/packages/transport/test/modules/relationships/RelationshipsController.test.ts @@ -1,6 +1,6 @@ import { IDatabaseConnection } from "@js-soft/docdb-access-abstractions"; import { CoreDate, CoreId } from "@nmshd/core-types"; -import { AccountController, CachedRelationship, Identity, Relationship, RelationshipStatus, RelationshipTemplate, Transport } from "../../../src"; +import { AccountController, CachedRelationship, Identity, Relationship, RelationshipStatus, Transport } from "../../../src"; import { TestUtil } from "../../testHelpers/TestUtil"; describe("RelationshipsController", function () { @@ -23,7 +23,7 @@ describe("RelationshipsController", function () { expect(relationship.peer).toBeInstanceOf(Identity); expect(relationship.peer.address).toStrictEqual(peerAccount.identity.address); - expect(relationship.cache!.template).toBeInstanceOf(RelationshipTemplate); + expect(relationship.cache!.templateId).toBeInstanceOf(CoreId); expect(relationship.cache).toBeInstanceOf(CachedRelationship); expect(relationship.cachedAt).toBeInstanceOf(CoreDate); diff --git a/packages/transport/test/modules/relationships/decomposition.test.ts b/packages/transport/test/modules/relationships/decomposition.test.ts index d39ea5acb..eacc07e77 100644 --- a/packages/transport/test/modules/relationships/decomposition.test.ts +++ b/packages/transport/test/modules/relationships/decomposition.test.ts @@ -62,7 +62,7 @@ describe("Data cleanup after relationship decomposition", function () { }); test("templates should be deleted", async function () { - const templateForRelationship = await sender.relationshipTemplates.getRelationshipTemplate(relationship.cache!.template.id); + const templateForRelationship = await sender.relationshipTemplates.getRelationshipTemplate(relationship.cache!.templateId); const otherTemplate = await sender.relationshipTemplates.getRelationshipTemplate(templateId); expect(templateForRelationship).toBeUndefined(); expect(otherTemplate).toBeUndefined(); From 11a7178dacb7748012aab70dca15fe7631ec15e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Fri, 18 Oct 2024 15:41:11 +0200 Subject: [PATCH 2/7] refactor: remove template from relationship in runtime logic --- .../runtime/src/dataViews/DataViewExpander.ts | 7 ++----- packages/runtime/src/modules/RequestModule.ts | 16 +++++++++++++--- .../src/types/transport/RelationshipDTO.ts | 3 +-- .../transport/relationships/GetRelationships.ts | 10 ++++------ .../relationships/RelationshipMapper.ts | 3 +-- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/runtime/src/dataViews/DataViewExpander.ts b/packages/runtime/src/dataViews/DataViewExpander.ts index 0151742a7..8f245691d 100644 --- a/packages/runtime/src/dataViews/DataViewExpander.ts +++ b/packages/runtime/src/dataViews/DataViewExpander.ts @@ -1727,10 +1727,7 @@ export class DataViewExpander { } } - let direction = RelationshipDirection.Incoming; - if (!relationship.template.isOwn) { - direction = RelationshipDirection.Outgoing; - } + const direction = this.identityController.isMe(CoreAddress.from(relationship.auditLog[0].createdBy)) ? RelationshipDirection.Outgoing : RelationshipDirection.Incoming; let statusText = ""; switch (relationship.status) { @@ -1789,7 +1786,7 @@ export class DataViewExpander { attributeMap: attributesByType, items: expandedAttributes, nameMap: stringByType, - templateId: relationship.template.id, + templateId: relationship.templateId, auditLog: relationship.auditLog, creationContent: relationship.creationContent }; diff --git a/packages/runtime/src/modules/RequestModule.ts b/packages/runtime/src/modules/RequestModule.ts index 623a3eb89..1b6d19396 100644 --- a/packages/runtime/src/modules/RequestModule.ts +++ b/packages/runtime/src/modules/RequestModule.ts @@ -293,10 +293,20 @@ export class RequestModule extends RuntimeModule { } // only trigger for new relationships that were created from an own template - if (createdRelationship.status !== RelationshipStatus.Pending || !createdRelationship.template.isOwn) return; + const relationshipIsNotPending = createdRelationship.status !== RelationshipStatus.Pending; + const relationshipIsCreatedByCurrentAccount = createdRelationship.auditLog[0].createdBy === event.eventTargetAddress; + if (relationshipIsNotPending || relationshipIsCreatedByCurrentAccount) return; + + const templateId = createdRelationship.templateId; + + const templateResult = await services.transportServices.relationshipTemplates.getRelationshipTemplate({ id: templateId }); + if (templateResult.isError) { + this.logger.error(`Could not get template with id '${templateId}'. Root error:`, templateResult.error); + return; + } + + const template = templateResult.value; - const template = createdRelationship.template; - const templateId = template.id; // do not trigger for templates without the correct content type if (template.content["@type"] !== "RelationshipTemplateContent") return; if (createdRelationship.creationContent["@type"] !== "RelationshipCreationContent") { diff --git a/packages/runtime/src/types/transport/RelationshipDTO.ts b/packages/runtime/src/types/transport/RelationshipDTO.ts index e17040b0d..51c84bb14 100644 --- a/packages/runtime/src/types/transport/RelationshipDTO.ts +++ b/packages/runtime/src/types/transport/RelationshipDTO.ts @@ -1,6 +1,5 @@ import { ArbitraryRelationshipCreationContentJSON, RelationshipCreationContentJSON } from "@nmshd/content"; import { IdentityDTO } from "./IdentityDTO"; -import { RelationshipTemplateDTO } from "./RelationshipTemplateDTO"; export enum RelationshipStatus { Pending = "Pending", @@ -49,7 +48,7 @@ export interface PeerDeletionInfoDTO { export interface RelationshipDTO { id: string; - template: RelationshipTemplateDTO; + templateId: string; status: RelationshipStatus; peer: string; peerIdentity: IdentityDTO; diff --git a/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts b/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts index fa5b90a91..26232a474 100644 --- a/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts +++ b/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts @@ -1,9 +1,9 @@ import { QueryTranslator } from "@js-soft/docdb-querytranslator"; import { Result } from "@js-soft/ts-utils"; -import { CachedRelationship, Identity, Relationship, RelationshipsController, RelationshipTemplate } from "@nmshd/transport"; +import { CachedRelationship, Identity, Relationship, RelationshipsController } from "@nmshd/transport"; import { Inject } from "@nmshd/typescript-ioc"; import { nameof } from "ts-simple-nameof"; -import { RelationshipDTO, RelationshipTemplateDTO } from "../../../types"; +import { RelationshipDTO } from "../../../types"; import { SchemaRepository, SchemaValidator, UseCase } from "../../common"; import { RelationshipMapper } from "./RelationshipMapper"; @@ -28,12 +28,10 @@ export class GetRelationshipsUseCase extends UseCase((r) => r.peer)]: true, [nameof((r) => r.status)]: true, - [`${nameof((r) => r.template)}.${nameof((t) => t.id)}`]: true + [`${nameof((r) => r.templateId)}`]: true }, alias: { - [`${nameof((r) => r.template)}.${nameof((r) => r.id)}`]: `${nameof( - (r) => r.cache - )}.${nameof((r) => r.template)}.${nameof((r) => r.id)}`, + [`${nameof((r) => r.templateId)}`]: `${nameof((r) => r.cache)}.${nameof((r) => r.templateId)}`, [nameof((r) => r.status)]: nameof((r) => r.status), [nameof((r) => r.peer)]: `${nameof((r) => r.peer)}.${nameof((r) => r.address)}` } diff --git a/packages/runtime/src/useCases/transport/relationships/RelationshipMapper.ts b/packages/runtime/src/useCases/transport/relationships/RelationshipMapper.ts index 610b825d1..3438360ef 100644 --- a/packages/runtime/src/useCases/transport/relationships/RelationshipMapper.ts +++ b/packages/runtime/src/useCases/transport/relationships/RelationshipMapper.ts @@ -3,7 +3,6 @@ import { ArbitraryRelationshipCreationContent, RelationshipCreationContent } fro import { Relationship, RelationshipAuditLogEntry } from "@nmshd/transport"; import { RelationshipAuditLogEntryDTO, RelationshipDTO } from "../../../types"; import { RuntimeErrors } from "../../common"; -import { RelationshipTemplateMapper } from "../relationshipTemplates/RelationshipTemplateMapper"; export class RelationshipMapper { public static toRelationshipDTO(relationship: Relationship): RelationshipDTO { @@ -13,7 +12,7 @@ export class RelationshipMapper { return { id: relationship.id.toString(), - template: RelationshipTemplateMapper.toRelationshipTemplateDTO(relationship.cache.template), + templateId: relationship.cache.templateId.toString(), status: relationship.status, peer: relationship.peer.address.toString(), peerDeletionInfo: relationship.peerDeletionInfo?.toJSON(), From c5d04b468950975af4d263ce7801db8853c9c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 22 Oct 2024 09:43:45 +0200 Subject: [PATCH 3/7] fix: update more tests --- .../modules/requests/testHelpers/TestObjectFactory.ts | 8 ++++---- packages/runtime/test/consumption/requests.test.ts | 2 +- packages/runtime/test/dataViews/RelationshipDVO.test.ts | 4 ++-- packages/runtime/test/lib/testUtils.ts | 3 ++- packages/runtime/test/transport/relationships.test.ts | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts b/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts index 547f95f06..c0208423b 100644 --- a/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts +++ b/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts @@ -64,7 +64,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.Pending } ], - template: this.createIncomingRelationshipTemplate() + templateId: { id: "b9uMR7u7lsKLzRfVJNYb" } }) }); } @@ -106,7 +106,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.Active } ], - template: this.createIncomingRelationshipTemplate() + templateId: { id: "b9uMR7u7lsKLzRfVJNYb" } }) }); } @@ -157,7 +157,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.Terminated } ], - template: this.createIncomingRelationshipTemplate() + templateId: { id: "b9uMR7u7lsKLzRfVJNYb" } }) }); } @@ -217,7 +217,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.DeletionProposed } ], - template: this.createIncomingRelationshipTemplate() + templateId: { id: "b9uMR7u7lsKLzRfVJNYb" } }) }); } diff --git a/packages/runtime/test/consumption/requests.test.ts b/packages/runtime/test/consumption/requests.test.ts index 580468ad5..113b245ee 100644 --- a/packages/runtime/test/consumption/requests.test.ts +++ b/packages/runtime/test/consumption/requests.test.ts @@ -580,7 +580,7 @@ describe("Requests", () => { const completionResult = await sConsumptionServices.outgoingRequests.createAndCompleteFromRelationshipTemplateResponse({ responseSourceId: sRelationship.id, response: (sRelationship.creationContent as RelationshipCreationContentJSON).response, - templateId: relationship!.template.id + templateId: relationship!.templateId }); expect(completionResult).toBeSuccessful(); diff --git a/packages/runtime/test/dataViews/RelationshipDVO.test.ts b/packages/runtime/test/dataViews/RelationshipDVO.test.ts index cae3cead6..cd4e44b59 100644 --- a/packages/runtime/test/dataViews/RelationshipDVO.test.ts +++ b/packages/runtime/test/dataViews/RelationshipDVO.test.ts @@ -80,7 +80,7 @@ describe("RelationshipDVO", () => { expect(dvo.relationship!.status).toBe("Active"); expect(dvo.relationship!.statusText).toBe("i18n://dvo.relationship.Active"); - expect(dvo.relationship!.templateId).toBe(dto.template.id); + expect(dvo.relationship!.templateId).toBe(dto.templateId); }); test("check the relationship dvo for the requestor", async () => { @@ -100,7 +100,7 @@ describe("RelationshipDVO", () => { expect(dvo.relationship!.status).toBe("Active"); expect(dvo.relationship!.statusText).toBe("i18n://dvo.relationship.Active"); - expect(dvo.relationship!.templateId).toBe(dto.template.id); + expect(dvo.relationship!.templateId).toBe(dto.templateId); }); test("check the relationship dvo for the templator with active relationshipSetting", async () => { diff --git a/packages/runtime/test/lib/testUtils.ts b/packages/runtime/test/lib/testUtils.ts index eb4432d6b..0968c0367 100644 --- a/packages/runtime/test/lib/testUtils.ts +++ b/packages/runtime/test/lib/testUtils.ts @@ -469,7 +469,8 @@ export async function ensureActiveRelationship(sTransportServices: TransportServ await rTransportServices.relationships.decomposeRelationship({ relationshipId: relationship.id }); await establishRelationship(sTransportServices, rTransportServices); } else if (sRelationships[0].status === RelationshipStatus.Pending) { - if (sRelationships[0].template.isOwn) { + const sRelationshipTemplate = await sTransportServices.relationshipTemplates.getRelationshipTemplate({ id: sRelationships[0].templateId }); + if (sRelationshipTemplate.value.isOwn) { const relationship = sRelationships[0]; await sTransportServices.relationships.acceptRelationship({ relationshipId: relationship.id }); await syncUntilHasRelationships(rTransportServices, 1); diff --git a/packages/runtime/test/transport/relationships.test.ts b/packages/runtime/test/transport/relationships.test.ts index 406d4f4f5..b66037e39 100644 --- a/packages/runtime/test/transport/relationships.test.ts +++ b/packages/runtime/test/transport/relationships.test.ts @@ -733,7 +733,7 @@ describe("RelationshipDecomposition", () => { beforeAll(async () => { const relationship = await ensureActiveRelationship(services1.transport, services2.transport); relationshipId = relationship.id; - templateId = relationship.template.id; + templateId = relationship.templateId; await createRelationshipData(services1, services2); @@ -741,7 +741,7 @@ describe("RelationshipDecomposition", () => { services3 = runtimeServices[0]; const relationship2 = await establishRelationship(services1.transport, services3.transport); relationshipId2 = relationship2.id; - templateId2 = relationship2.template.id; + templateId2 = relationship2.templateId; await createRelationshipData(services1, services3); multipleRecipientsMessageId = (await sendMessageToMultipleRecipients(services1.transport, [services2.address, services3.address])).id; From 32c91c5f273c3fcad495e5a0f574fde7fd52ea75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 22 Oct 2024 09:54:48 +0200 Subject: [PATCH 4/7] fix: revocation test --- packages/transport/test/end2end/End2End.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/transport/test/end2end/End2End.test.ts b/packages/transport/test/end2end/End2End.test.ts index 880021fa6..2526da0ff 100644 --- a/packages/transport/test/end2end/End2End.test.ts +++ b/packages/transport/test/end2end/End2End.test.ts @@ -311,7 +311,7 @@ describe("RelationshipTest: Revoke", function () { expect(revokedRelationshipSelf.cache?.auditLog).toHaveLength(2); expect(revokedRelationshipSelf.cache!.auditLog[1].newStatus).toBe(RelationshipStatus.Revoked); expect(revokedRelationshipSelf.peer).toBeDefined(); - expect(revokedRelationshipSelf.peer.address.toString()).toStrictEqual(revokedRelationshipSelf.cache!.auditLog[0].createdBy.toString()); + expect(revokedRelationshipSelf.peer.address.toString()).toStrictEqual(revokedRelationshipSelf.cache!.auditLog[1].createdBy.toString()); const syncedRelationshipsPeer = await TestUtil.syncUntilHasRelationships(templator); expect(syncedRelationshipsPeer).toHaveLength(1); From 5d506125c38556fe00ff57b0ff5bb93204f11ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Tue, 22 Oct 2024 09:57:14 +0200 Subject: [PATCH 5/7] fix: query relationships --- packages/runtime/src/useCases/common/Schemas.ts | 2 +- .../src/useCases/transport/relationships/GetRelationships.ts | 2 +- packages/runtime/test/transport/relationships.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/runtime/src/useCases/common/Schemas.ts b/packages/runtime/src/useCases/common/Schemas.ts index 1269dc45a..8ac9cbeb8 100644 --- a/packages/runtime/src/useCases/common/Schemas.ts +++ b/packages/runtime/src/useCases/common/Schemas.ts @@ -22519,7 +22519,7 @@ export const GetRelationshipsRequest: any = { } ] }, - "template.id": { + "templateId": { "anyOf": [ { "type": "string" diff --git a/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts b/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts index 26232a474..e03c24542 100644 --- a/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts +++ b/packages/runtime/src/useCases/transport/relationships/GetRelationships.ts @@ -10,7 +10,7 @@ import { RelationshipMapper } from "./RelationshipMapper"; export interface GetRelationshipsQuery { peer?: string | string[]; status?: string | string[]; - "template.id"?: string | string[]; + templateId?: string | string[]; } export interface GetRelationshipsRequest { diff --git a/packages/runtime/test/transport/relationships.test.ts b/packages/runtime/test/transport/relationships.test.ts index b66037e39..b058ff343 100644 --- a/packages/runtime/test/transport/relationships.test.ts +++ b/packages/runtime/test/transport/relationships.test.ts @@ -238,7 +238,7 @@ describe("Relationships query", () => { const conditions = new QueryParamConditions(relationship, services1.transport) .addStringSet("peer") .addStringSet("status") - .addStringSet("template.id"); + .addStringSet("templateId"); await conditions.executeTests((c, q) => c.relationships.getRelationships({ query: q })); }); }); From 9b079c5046825f54aedc5bd2107df110bdddbf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Wed, 23 Oct 2024 14:45:44 +0200 Subject: [PATCH 6/7] fix: remove strange check --- packages/transport/test/end2end/End2End.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/transport/test/end2end/End2End.test.ts b/packages/transport/test/end2end/End2End.test.ts index 2526da0ff..1d57c7855 100644 --- a/packages/transport/test/end2end/End2End.test.ts +++ b/packages/transport/test/end2end/End2End.test.ts @@ -310,8 +310,6 @@ describe("RelationshipTest: Revoke", function () { expect(revokedRelationshipSelf.status).toStrictEqual(RelationshipStatus.Revoked); expect(revokedRelationshipSelf.cache?.auditLog).toHaveLength(2); expect(revokedRelationshipSelf.cache!.auditLog[1].newStatus).toBe(RelationshipStatus.Revoked); - expect(revokedRelationshipSelf.peer).toBeDefined(); - expect(revokedRelationshipSelf.peer.address.toString()).toStrictEqual(revokedRelationshipSelf.cache!.auditLog[1].createdBy.toString()); const syncedRelationshipsPeer = await TestUtil.syncUntilHasRelationships(templator); expect(syncedRelationshipsPeer).toHaveLength(1); From 87d767496574fe131033f7ac12b8272a46635e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20K=C3=B6nig?= Date: Fri, 13 Dec 2024 21:44:38 +0100 Subject: [PATCH 7/7] fix: template usage --- .../test/modules/requests/testHelpers/TestObjectFactory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts b/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts index 271b87356..9afeae64f 100644 --- a/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts +++ b/packages/consumption/test/modules/requests/testHelpers/TestObjectFactory.ts @@ -209,7 +209,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.Active } ], - template: this.createIncomingRelationshipTemplate() + templateId: CoreId.from("aTemplateId") }) }); } @@ -266,7 +266,7 @@ export class TestObjectFactory { newStatus: RelationshipStatus.DeletionProposed } ], - template: this.createIncomingRelationshipTemplate() + templateId: CoreId.from("aTemplateId") }) }); }