Skip to content

Commit

Permalink
Update ThirdPartyRelationshipAttribute nomenclature (#304)
Browse files Browse the repository at this point in the history
* feat: remove ThirdPartyOwnedRelationship and add ThirdPartyRelationshipAttribute to LocalAttribute

* feat: replace ThirdPartyOwnedRA deletion by ThirdPartyRA deletion

* feat: replace third party owned succession by ThirdPartyRA succession

* feat: adjust tests

* refactor: use wording emitted instead of own shared

* fix: rebasing

* feat: clean up PR

* feat: re-add deprecated ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItem for backwards-campatibility

* feat: re-add runtime ThirdPartyOwnedRelationshipAttributeDeletedByPeerEvent for backwards-compatibility

* feat: simplify deprecation of ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItem

* feat: re-add deprecated deleteThirdPartyOwnedRelationshipAttributeAndNotifyPeer for backwards-compatibility

* feat: integrate comments

* refactor: ThirdPartyRelationshipAttributeDeletedByPeerNotificationItem test

---------

Co-authored-by: Julian König <33655937+jkoenig134@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 7b0bb79 commit d2de563
Show file tree
Hide file tree
Showing 31 changed files with 365 additions and 332 deletions.
6 changes: 3 additions & 3 deletions packages/consumption/src/consumption/ConsumptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ReadAttributeRequestItem,
RegisterAttributeListenerRequestItem,
ShareAttributeRequestItem,
ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItem
ThirdPartyRelationshipAttributeDeletedByPeerNotificationItem
} from "@nmshd/content";
import { CoreAddress, CoreId } from "@nmshd/core-types";
import { AccountController, Transport } from "@nmshd/transport";
Expand Down Expand Up @@ -41,7 +41,7 @@ import {
RequestItemProcessorRegistry,
SettingsController,
ShareAttributeRequestItemProcessor,
ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItemProcessor
ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor
} from "../modules";
import { ConsumptionConfig } from "./ConsumptionConfig";

Expand Down Expand Up @@ -168,7 +168,7 @@ export class ConsumptionController {
[PeerSharedAttributeSucceededNotificationItem, PeerSharedAttributeSucceededNotificationItemProcessor],
[OwnSharedAttributeDeletedByOwnerNotificationItem, OwnSharedAttributeDeletedByOwnerNotificationItemProcessor],
[PeerSharedAttributeDeletedByPeerNotificationItem, PeerSharedAttributeDeletedByPeerNotificationItemProcessor],
[ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItem, ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItemProcessor]
[ThirdPartyRelationshipAttributeDeletedByPeerNotificationItem, ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor]
]);
}

Expand Down
27 changes: 15 additions & 12 deletions packages/consumption/src/consumption/ConsumptionCoreErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class Attributes {
return new CoreError("error.consumption.attributes.predecessorIsNotPeerSharedRelationshipAttribute", "Predecessor is not a peer shared RelationshipAttribute.");
}

public predecessorIsNotThirdPartyOwnedRelationshipAttribute() {
return new CoreError("error.consumption.attributes.predecessorIsNotThirdPartyOwnedRelationshipAttribute", "Predecessor is not a third party owned RelationshipAttribute.");
public predecessorIsNotThirdPartyRelationshipAttribute() {
return new CoreError("error.consumption.attributes.predecessorIsNotThirdPartyRelationshipAttribute", "Predecessor is not a ThirdPartyRelationshipAttribute.");
}

public successorIsNotRepositoryAttribute() {
Expand All @@ -116,8 +116,8 @@ class Attributes {
return new CoreError("error.consumption.attributes.successorIsNotPeerSharedRelationshipAttribute", "Successor is not a peer shared RelationshipAttribute.");
}

public successorIsNotThirdPartyOwnedRelationshipAttribute() {
return new CoreError("error.consumption.attributes.successorIsNotThirdPartyOwnedRelationshipAttribute", "Successor is not a third party owned RelationshipAttribute.");
public successorIsNotThirdPartyRelationshipAttribute() {
return new CoreError("error.consumption.attributes.successorIsNotThirdPartyRelationshipAttribute", "Successor is not a ThirdPartyRelationshipAttribute.");
}

public setPredecessorIdDoesNotMatchActualPredecessorId() {
Expand Down Expand Up @@ -170,6 +170,12 @@ class Attributes {
return new CoreError("error.consumption.attributes.successionMustNotChangePeer", errorMessage);
}

public successionMustNotChangeThirdParty(comment?: string) {
let errorMessage = "The thirdPartyAddress of the shared Attribute must not change.";
if (comment) errorMessage += ` ${comment}`;
return new CoreError("error.consumption.attributes.successionMustNotChangeThirdParty", errorMessage);
}

public cannotSucceedAttributesWithASuccessor(successorId: string | CoreId) {
return new CoreError(
"error.consumption.attributes.cannotSucceedAttributesWithASuccessor",
Expand Down Expand Up @@ -209,10 +215,10 @@ class Attributes {
);
}

public invalidDeletionInfoOfThirdPartyOwnedRelationshipAttribute() {
public invalidDeletionInfoOfThirdPartyRelationshipAttribute() {
return new CoreError(
"error.consumption.attributes.invalidDeletionInfoOfThirdPartyOwnedRelationshipAttribute",
"The only valid deletionStatus for third party owned RelationshipAttributes is 'DeletedByPeer'."
"error.consumption.attributes.invalidDeletionInfoOfThirdPartyRelationshipAttribute",
"The only valid deletionStatus for ThirdPartyRelationshipAttributes is 'DeletedByPeer'."
);
}

Expand All @@ -239,11 +245,8 @@ class Attributes {
return new CoreError("error.consumption.attributes.isNotPeerSharedAttribute", `The Attribute (id: '${attributeId}') is not a peer shared Attribute.`);
}

public isNotThirdPartyOwnedRelationshipAttribute(attributeId: string | CoreId) {
return new CoreError(
"error.consumption.attributes.isNotThirdPartyOwnedRelationshipAttribute",
`The Attribute (id: '${attributeId}') is not a third party owned RelationshipAttribute.`
);
public isNotThirdPartyRelationshipAttribute(attributeId: string | CoreId) {
return new CoreError("error.consumption.attributes.isNotThirdPartyRelationshipAttribute", `The Attribute (id: '${attributeId}') is not a ThirdPartyRelationshipAttribute.`);
}

public senderIsNotPeerOfSharedAttribute(senderId: string | CoreAddress, attributeId: string | CoreId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
OwnSharedAttributeSucceededEvent,
RepositoryAttributeSucceededEvent,
SharedAttributeCopyCreatedEvent,
ThirdPartyOwnedRelationshipAttributeSucceededEvent
ThirdPartyRelationshipAttributeSucceededEvent
} from "./events";
import { AttributeSuccessorParams, AttributeSuccessorParamsJSON, IAttributeSuccessorParams } from "./local/AttributeSuccessorParams";
import { CreateRepositoryAttributeParams, ICreateRepositoryAttributeParams } from "./local/CreateRepositoryAttributeParams";
Expand Down Expand Up @@ -535,15 +535,15 @@ export class AttributesController extends ConsumptionBaseController {
return { predecessor, successor };
}

public async succeedThirdPartyOwnedRelationshipAttribute(
public async succeedThirdPartyRelationshipAttribute(
predecessorId: CoreId,
successorParams: IAttributeSuccessorParams | AttributeSuccessorParamsJSON,
validate = true
): Promise<{ predecessor: LocalAttribute; successor: LocalAttribute }> {
const parsedSuccessorParams = AttributeSuccessorParams.from(successorParams);

if (validate) {
const validationResult = await this.validateThirdPartyOwnedRelationshipAttributeSuccession(predecessorId, parsedSuccessorParams);
const validationResult = await this.validateThirdPartyRelationshipAttributeSuccession(predecessorId, parsedSuccessorParams);
if (validationResult.isError()) {
throw validationResult.error;
}
Expand All @@ -559,7 +559,7 @@ export class AttributesController extends ConsumptionBaseController {
succeededBy: parsedSuccessorParams.succeededBy
});

this.eventBus.publish(new ThirdPartyOwnedRelationshipAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
this.eventBus.publish(new ThirdPartyRelationshipAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));

return { predecessor, successor };
}
Expand Down Expand Up @@ -887,7 +887,7 @@ export class AttributesController extends ConsumptionBaseController {
return ValidationResult.success();
}

public async validateThirdPartyOwnedRelationshipAttributeSuccession(
public async validateThirdPartyRelationshipAttributeSuccession(
predecessorId: CoreId,
successorParams: IAttributeSuccessorParams | AttributeSuccessorParamsJSON
): Promise<ValidationResult> {
Expand All @@ -912,12 +912,12 @@ export class AttributesController extends ConsumptionBaseController {
parentId: parsedSuccessorParams.parentId
});

if (!predecessor.isThirdPartyOwnedRelationshipAttribute(this.identity.address)) {
return ValidationResult.error(ConsumptionCoreErrors.attributes.predecessorIsNotThirdPartyOwnedRelationshipAttribute());
if (!predecessor.isThirdPartyRelationshipAttribute()) {
return ValidationResult.error(ConsumptionCoreErrors.attributes.predecessorIsNotThirdPartyRelationshipAttribute());
}

if (!successor.isThirdPartyOwnedRelationshipAttribute(this.identity.address)) {
return ValidationResult.error(ConsumptionCoreErrors.attributes.successorIsNotThirdPartyOwnedRelationshipAttribute());
if (!successor.isThirdPartyRelationshipAttribute()) {
return ValidationResult.error(ConsumptionCoreErrors.attributes.successorIsNotThirdPartyRelationshipAttribute());
}

if (successor.content.key !== predecessor.content.key) {
Expand All @@ -928,6 +928,10 @@ export class AttributesController extends ConsumptionBaseController {
return ValidationResult.error(ConsumptionCoreErrors.attributes.successionMustNotChangePeer());
}

if (!predecessor.shareInfo.thirdPartyAddress.equals(successor.shareInfo.thirdPartyAddress)) {
return ValidationResult.error(ConsumptionCoreErrors.attributes.successionMustNotChangeThirdParty());
}

return ValidationResult.success();
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { TransportDataEvent } from "@nmshd/transport";
import { LocalAttribute } from "../local/LocalAttribute";

export class ThirdPartyRelationshipAttributeDeletedByPeerEvent extends TransportDataEvent<LocalAttribute> {
public static readonly namespace = "consumption.thirdPartyRelationshipAttributeDeletedByPeer";

public constructor(eventTargetAddress: string, data: LocalAttribute) {
super(ThirdPartyRelationshipAttributeDeletedByPeerEvent.namespace, eventTargetAddress, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TransportDataEvent } from "@nmshd/transport";
import { LocalAttribute } from "../local/LocalAttribute";
import { AttributeSucceededEventData } from "./AttributeSucceededEventData";

export class ThirdPartyRelationshipAttributeSucceededEvent extends TransportDataEvent<AttributeSucceededEventData> {
public static readonly namespace = "consumption.thirdPartyRelationshipAttributeSucceeded";

public constructor(eventTargetAddress: string, predecessor: LocalAttribute, successor: LocalAttribute) {
super(ThirdPartyRelationshipAttributeSucceededEvent.namespace, eventTargetAddress, { predecessor, successor });
}
}
4 changes: 2 additions & 2 deletions packages/consumption/src/modules/attributes/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export * from "./PeerSharedAttributeDeletedByPeerEvent";
export * from "./PeerSharedAttributeSucceededEvent";
export * from "./RepositoryAttributeSucceededEvent";
export * from "./SharedAttributeCopyCreatedEvent";
export * from "./ThirdPartyOwnedRelationshipAttributeDeletedByPeerEvent";
export * from "./ThirdPartyOwnedRelationshipAttributeSucceededEvent";
export * from "./ThirdPartyRelationshipAttributeDeletedByPeerEvent";
export * from "./ThirdPartyRelationshipAttributeSucceededEvent";
59 changes: 14 additions & 45 deletions packages/consumption/src/modules/attributes/local/LocalAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ export type OwnSharedRelationshipAttribute = LocalAttribute & {
isDefault: undefined;
};

export type OwnSharedThirdPartyRelationshipAttribute = OwnSharedRelationshipAttribute & {
shareInfo: OwnSharedRelationshipAttribute["shareInfo"] & {
thirdPartyAddress: CoreAddress;
};
};

export type PeerSharedIdentityAttribute = LocalAttribute & {
content: IdentityAttribute;
shareInfo: LocalAttributeShareInfo & { sourceAttribute: undefined };
Expand All @@ -72,15 +66,9 @@ export type PeerSharedRelationshipAttribute = LocalAttribute & {
isDefault: undefined;
};

export type PeerSharedThirdPartyRelationshipAttribute = PeerSharedRelationshipAttribute & {
shareInfo: PeerSharedRelationshipAttribute["shareInfo"] & {
thirdPartyAddress: CoreAddress;
};
};

export type ThirdPartyOwnedRelationshipAttribute = LocalAttribute & {
export type ThirdPartyRelationshipAttribute = LocalAttribute & {
content: RelationshipAttribute;
shareInfo: LocalAttribute["shareInfo"] & {
shareInfo: LocalAttributeShareInfo & {
thirdPartyAddress: CoreAddress;
};
parentId: undefined;
Expand Down Expand Up @@ -157,8 +145,8 @@ export class LocalAttribute extends CoreSynchronizable implements ILocalAttribut
return this.isRelationshipAttribute() && this.isPeerSharedAttribute(peerAddress);
}

public isThirdPartyOwnedRelationshipAttribute(ownAddress: CoreAddress, thirdPartyAddress?: CoreAddress): this is ThirdPartyOwnedRelationshipAttribute {
return this.isRelationshipAttribute() && this.isThirdPartyOwnedAttribute(ownAddress, thirdPartyAddress);
public isThirdPartyRelationshipAttribute(): this is ThirdPartyRelationshipAttribute {
return this.isRelationshipAttribute() && !!this.shareInfo.thirdPartyAddress;
}

public isRepositoryAttribute(ownAddress: CoreAddress): this is RepositoryAttribute {
Expand Down Expand Up @@ -187,36 +175,17 @@ export class LocalAttribute extends CoreSynchronizable implements ILocalAttribut
return isPeerSharedAttribute;
}

public isOwnSharedThirdPartyRelationshipAttribute(ownAddress: CoreAddress): this is OwnSharedThirdPartyRelationshipAttribute {
const isThirdPartyAttribute = !!this.shareInfo?.thirdPartyAddress;
const isOwnShared = this.isOwnedBy(ownAddress);
return isThirdPartyAttribute && isOwnShared;
}

public isPeerSharedThirdPartyRelationshipAttribute(peerAddress: CoreAddress): this is PeerSharedThirdPartyRelationshipAttribute {
const isThirdPartyAttribute = !!this.shareInfo?.thirdPartyAddress;
const isPeerShared = this.isOwnedBy(peerAddress);
return isThirdPartyAttribute && isPeerShared;
}

public isThirdPartyOwnedAttribute(ownAddress: CoreAddress, thirdPartyAddress?: CoreAddress): this is ThirdPartyOwnedRelationshipAttribute {
let isThirdPartyOwnedAttribute = this.isShared() && !this.isOwnedBy(ownAddress) && !this.isOwnedBy(this.shareInfo.peer);

isThirdPartyOwnedAttribute &&= !this.parentId;
isThirdPartyOwnedAttribute &&= !this.isDefault;

if (thirdPartyAddress) isThirdPartyOwnedAttribute &&= this.isOwnedBy(thirdPartyAddress);
return isThirdPartyOwnedAttribute;
}

public isIdentityAttribute(): this is LocalAttribute & { content: IdentityAttribute } {
return this.content instanceof IdentityAttribute;
}

public isRelationshipAttribute(): this is LocalAttribute & { content: RelationshipAttribute } & {
shareInfo: LocalAttributeShareInfo;
} {
return this.content instanceof RelationshipAttribute && this.isShared();
public isRelationshipAttribute(): this is LocalAttribute & { content: RelationshipAttribute; shareInfo: LocalAttributeShareInfo } {
let isRelationshipAttribute = this.content instanceof RelationshipAttribute && this.isShared();

isRelationshipAttribute &&= !this.parentId;
isRelationshipAttribute &&= !this.isDefault;

return isRelationshipAttribute;
}

public isComplexAttribute(): boolean {
Expand Down Expand Up @@ -244,8 +213,8 @@ export class LocalAttribute extends CoreSynchronizable implements ILocalAttribut
throw ConsumptionCoreErrors.attributes.invalidDeletionInfoOfPeerSharedAttribute();
}

if (this.isThirdPartyOwnedRelationshipAttribute(ownAddress) && !this.isThirdPartyOwnedRelationshipAttributeDeletionInfo(deletionInfo)) {
throw ConsumptionCoreErrors.attributes.invalidDeletionInfoOfThirdPartyOwnedRelationshipAttribute();
if (this.isThirdPartyRelationshipAttribute() && !this.isThirdPartyRelationshipAttributeDeletionInfo(deletionInfo)) {
throw ConsumptionCoreErrors.attributes.invalidDeletionInfoOfThirdPartyRelationshipAttribute();
}

this.deletionInfo = deletionInfo;
Expand All @@ -265,7 +234,7 @@ export class LocalAttribute extends CoreSynchronizable implements ILocalAttribut
);
}

private isThirdPartyOwnedRelationshipAttributeDeletionInfo(deletionInfo: LocalAttributeDeletionInfo): boolean {
private isThirdPartyRelationshipAttributeDeletionInfo(deletionInfo: LocalAttributeDeletionInfo): boolean {
return deletionInfo.deletionStatus === LocalAttributeDeletionStatus.DeletedByPeer;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/consumption/src/modules/notifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from "./itemProcessors/AbstractNotificationItemProcessor";
export * from "./itemProcessors/attributeDeleted/OwnSharedAttributeDeletedByOwnerNotificationItemProcessor";
export * from "./itemProcessors/attributeDeleted/PeerSharedAttributeDeletedByPeerNotificationItemProcessor";
export * from "./itemProcessors/attributeDeleted/ThirdPartyOwnedRelationshipAttributeDeletedByPeerNotificationItemProcessor";
export * from "./itemProcessors/attributeDeleted/ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor";
export * from "./itemProcessors/attributeSucceeded/PeerSharedAttributeSucceededNotificationItemProcessor";
export * from "./itemProcessors/NotificationItemConstructor";
export * from "./itemProcessors/NotificationItemProcessorConstructor";
Expand Down
Loading

0 comments on commit d2de563

Please sign in to comment.