Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ThirdPartyRelationshipAttribute nomenclature #304

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
957b841
feat: remove ThirdPartyOwnedRelationship and add ThirdPartyRelationsh…
Milena-Czierlinski Oct 21, 2024
d48c757
feat: replace ThirdPartyOwnedRA deletion by ThirdPartyRA deletion
Milena-Czierlinski Oct 21, 2024
7fbe80a
feat: replace third party owned succession by ThirdPartyRA succession
Milena-Czierlinski Oct 21, 2024
a86970c
feat: adjust tests
Milena-Czierlinski Oct 21, 2024
be6c0d7
refactor: use wording emitted instead of own shared
Milena-Czierlinski Oct 21, 2024
7af1f3e
fix: rebasing
Milena-Czierlinski Oct 21, 2024
64d1a38
feat: clean up PR
Milena-Czierlinski Oct 21, 2024
f6f0628
Merge branch 'main' into feature/third-party-relationship-attribute-n…
jkoenig134 Oct 22, 2024
c41b3cb
Merge branch 'main' into feature/third-party-relationship-attribute-n…
mergify[bot] Oct 22, 2024
11b5d80
feat: re-add deprecated ThirdPartyOwnedRelationshipAttributeDeletedBy…
Milena-Czierlinski Oct 23, 2024
9688b9a
feat: re-add runtime ThirdPartyOwnedRelationshipAttributeDeletedByPee…
Milena-Czierlinski Oct 23, 2024
54e55da
Merge branch 'feature/third-party-relationship-attribute-nomenclature…
Milena-Czierlinski Oct 23, 2024
2b59963
feat: simplify deprecation of ThirdPartyOwnedRelationshipAttributeDel…
Milena-Czierlinski Oct 23, 2024
c8fcc62
feat: re-add deprecated deleteThirdPartyOwnedRelationshipAttributeAnd…
Milena-Czierlinski Oct 23, 2024
4973188
feat: integrate comments
Milena-Czierlinski Oct 23, 2024
056f22f
refactor: ThirdPartyRelationshipAttributeDeletedByPeerNotificationIte…
Milena-Czierlinski Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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