@nmshd/consumption 7.0.0-alpha.70 → 7.0.0-alpha.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildInformation.js +4 -4
- package/dist/consumption/ConsumptionConfig.d.ts +1 -1
- package/dist/consumption/ConsumptionConfig.d.ts.map +1 -1
- package/dist/consumption/ConsumptionController.d.ts.map +1 -1
- package/dist/consumption/ConsumptionController.js +5 -5
- package/dist/consumption/ConsumptionController.js.map +1 -1
- package/dist/consumption/ConsumptionCoreErrors.d.ts +7 -37
- package/dist/consumption/ConsumptionCoreErrors.d.ts.map +1 -1
- package/dist/consumption/ConsumptionCoreErrors.js +18 -114
- package/dist/consumption/ConsumptionCoreErrors.js.map +1 -1
- package/dist/consumption/ConsumptionIds.d.ts +1 -0
- package/dist/consumption/ConsumptionIds.d.ts.map +1 -1
- package/dist/consumption/ConsumptionIds.js +1 -0
- package/dist/consumption/ConsumptionIds.js.map +1 -1
- package/dist/modules/attributes/AttributesController.d.ts +106 -69
- package/dist/modules/attributes/AttributesController.d.ts.map +1 -1
- package/dist/modules/attributes/AttributesController.js +640 -732
- package/dist/modules/attributes/AttributesController.js.map +1 -1
- package/dist/modules/attributes/events/AttributeCreatedEvent.d.ts +1 -1
- package/dist/modules/attributes/events/AttributeCreatedEvent.d.ts.map +1 -1
- package/dist/modules/attributes/events/AttributeDeletedEvent.d.ts +1 -1
- package/dist/modules/attributes/events/AttributeDeletedEvent.d.ts.map +1 -1
- package/dist/modules/attributes/events/AttributeForwardingDetailsChangedEvent.d.ts +9 -0
- package/dist/modules/attributes/events/AttributeForwardingDetailsChangedEvent.d.ts.map +1 -0
- package/dist/modules/attributes/events/AttributeForwardingDetailsChangedEvent.js +12 -0
- package/dist/modules/attributes/events/AttributeForwardingDetailsChangedEvent.js.map +1 -0
- package/dist/modules/attributes/events/AttributeSucceededEvent.d.ts +11 -0
- package/dist/modules/attributes/events/AttributeSucceededEvent.d.ts.map +1 -0
- package/dist/modules/attributes/events/AttributeSucceededEvent.js +12 -0
- package/dist/modules/attributes/events/AttributeSucceededEvent.js.map +1 -0
- package/dist/modules/attributes/events/AttributeWasViewedAtChangedEvent.d.ts +1 -1
- package/dist/modules/attributes/events/AttributeWasViewedAtChangedEvent.d.ts.map +1 -1
- package/dist/modules/attributes/events/ForwardedAttributeDeletedByPeerEvent.d.ts +7 -0
- package/dist/modules/attributes/events/ForwardedAttributeDeletedByPeerEvent.d.ts.map +1 -0
- package/dist/modules/attributes/events/ForwardedAttributeDeletedByPeerEvent.js +12 -0
- package/dist/modules/attributes/events/ForwardedAttributeDeletedByPeerEvent.js.map +1 -0
- package/dist/modules/attributes/events/OwnAttributeDeletedByOwnerEvent.d.ts +7 -0
- package/dist/modules/attributes/events/OwnAttributeDeletedByOwnerEvent.d.ts.map +1 -0
- package/dist/modules/attributes/events/OwnAttributeDeletedByOwnerEvent.js +12 -0
- package/dist/modules/attributes/events/OwnAttributeDeletedByOwnerEvent.js.map +1 -0
- package/dist/modules/attributes/events/PeerRelationshipAttributeDeletedByPeerEvent.d.ts +7 -0
- package/dist/modules/attributes/events/PeerRelationshipAttributeDeletedByPeerEvent.d.ts.map +1 -0
- package/dist/modules/attributes/events/PeerRelationshipAttributeDeletedByPeerEvent.js +12 -0
- package/dist/modules/attributes/events/PeerRelationshipAttributeDeletedByPeerEvent.js.map +1 -0
- package/dist/modules/attributes/events/index.d.ts +5 -9
- package/dist/modules/attributes/events/index.d.ts.map +1 -1
- package/dist/modules/attributes/events/index.js +5 -9
- package/dist/modules/attributes/events/index.js.map +1 -1
- package/dist/modules/attributes/index.d.ts +9 -7
- package/dist/modules/attributes/index.d.ts.map +1 -1
- package/dist/modules/attributes/index.js +9 -7
- package/dist/modules/attributes/index.js.map +1 -1
- package/dist/modules/attributes/local/AttributeForwardingDetails.d.ts +28 -0
- package/dist/modules/attributes/local/AttributeForwardingDetails.d.ts.map +1 -0
- package/dist/modules/attributes/local/AttributeForwardingDetails.js +62 -0
- package/dist/modules/attributes/local/AttributeForwardingDetails.js.map +1 -0
- package/dist/modules/attributes/local/QueryTranslator.d.ts.map +1 -1
- package/dist/modules/attributes/local/QueryTranslator.js +1 -1
- package/dist/modules/attributes/local/QueryTranslator.js.map +1 -1
- package/dist/modules/attributes/local/attributeTypes/LocalAttribute.d.ts +29 -0
- package/dist/modules/attributes/local/attributeTypes/LocalAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/{AttributeSuccessorParams.js → attributeTypes/LocalAttribute.js} +34 -26
- package/dist/modules/attributes/local/attributeTypes/LocalAttribute.js.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/OwnIdentityAttribute.d.ts +19 -0
- package/dist/modules/attributes/local/attributeTypes/OwnIdentityAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/OwnIdentityAttribute.js +40 -0
- package/dist/modules/attributes/local/attributeTypes/OwnIdentityAttribute.js.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/OwnRelationshipAttribute.d.ts +29 -0
- package/dist/modules/attributes/local/attributeTypes/OwnRelationshipAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/OwnRelationshipAttribute.js +73 -0
- package/dist/modules/attributes/local/attributeTypes/OwnRelationshipAttribute.js.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/PeerIdentityAttribute.d.ts +29 -0
- package/dist/modules/attributes/local/attributeTypes/PeerIdentityAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/PeerIdentityAttribute.js +76 -0
- package/dist/modules/attributes/local/attributeTypes/PeerIdentityAttribute.js.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/PeerRelationshipAttribute.d.ts +30 -0
- package/dist/modules/attributes/local/attributeTypes/PeerRelationshipAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/PeerRelationshipAttribute.js +76 -0
- package/dist/modules/attributes/local/attributeTypes/PeerRelationshipAttribute.js.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/ThirdPartyRelationshipAttribute.d.ts +33 -0
- package/dist/modules/attributes/local/attributeTypes/ThirdPartyRelationshipAttribute.d.ts.map +1 -0
- package/dist/modules/attributes/local/attributeTypes/ThirdPartyRelationshipAttribute.js +85 -0
- package/dist/modules/attributes/local/attributeTypes/ThirdPartyRelationshipAttribute.js.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/AbstractAttributeDeletionInfo.d.ts +15 -0
- package/dist/modules/attributes/local/deletionInfos/AbstractAttributeDeletionInfo.d.ts.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/AbstractAttributeDeletionInfo.js +28 -0
- package/dist/modules/attributes/local/deletionInfos/AbstractAttributeDeletionInfo.js.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/EmittedAttributeDeletionInfo.d.ts +18 -0
- package/dist/modules/attributes/local/deletionInfos/EmittedAttributeDeletionInfo.d.ts.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/EmittedAttributeDeletionInfo.js +38 -0
- package/dist/modules/attributes/local/deletionInfos/EmittedAttributeDeletionInfo.js.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/ReceivedAttributeDeletionInfo.d.ts +16 -0
- package/dist/modules/attributes/local/deletionInfos/ReceivedAttributeDeletionInfo.d.ts.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/ReceivedAttributeDeletionInfo.js +36 -0
- package/dist/modules/attributes/local/deletionInfos/ReceivedAttributeDeletionInfo.js.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/index.d.ts +4 -0
- package/dist/modules/attributes/local/deletionInfos/index.d.ts.map +1 -0
- package/dist/modules/attributes/local/deletionInfos/index.js +20 -0
- package/dist/modules/attributes/local/deletionInfos/index.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/OwnIdentityAttributeSuccessorParams.d.ts +13 -0
- package/dist/modules/attributes/local/successorParams/OwnIdentityAttributeSuccessorParams.d.ts.map +1 -0
- package/dist/modules/attributes/local/successorParams/OwnIdentityAttributeSuccessorParams.js +29 -0
- package/dist/modules/attributes/local/successorParams/OwnIdentityAttributeSuccessorParams.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/OwnRelationshipAttributeSuccessorParams.d.ts +17 -0
- package/dist/modules/attributes/local/successorParams/OwnRelationshipAttributeSuccessorParams.d.ts.map +1 -0
- package/dist/modules/attributes/local/{CreateAttributeParams.js → successorParams/OwnRelationshipAttributeSuccessorParams.js} +10 -15
- package/dist/modules/attributes/local/successorParams/OwnRelationshipAttributeSuccessorParams.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/PeerIdentityAttributeSuccessorParams.d.ts +20 -0
- package/dist/modules/attributes/local/successorParams/PeerIdentityAttributeSuccessorParams.d.ts.map +1 -0
- package/dist/modules/attributes/local/{CreateRepositoryAttributeParams.js → successorParams/PeerIdentityAttributeSuccessorParams.js} +16 -13
- package/dist/modules/attributes/local/successorParams/PeerIdentityAttributeSuccessorParams.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/PeerRelationshipAttributeSuccessorParams.d.ts +20 -0
- package/dist/modules/attributes/local/successorParams/PeerRelationshipAttributeSuccessorParams.d.ts.map +1 -0
- package/dist/modules/attributes/local/{CreateSharedLocalAttributeCopyParams.js → successorParams/PeerRelationshipAttributeSuccessorParams.js} +15 -16
- package/dist/modules/attributes/local/successorParams/PeerRelationshipAttributeSuccessorParams.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/ThirdPartyRelationshipAttributeSuccessorParams.d.ts +20 -0
- package/dist/modules/attributes/local/successorParams/ThirdPartyRelationshipAttributeSuccessorParams.d.ts.map +1 -0
- package/dist/modules/attributes/local/{CreateSharedLocalAttributeParams.js → successorParams/ThirdPartyRelationshipAttributeSuccessorParams.js} +15 -22
- package/dist/modules/attributes/local/successorParams/ThirdPartyRelationshipAttributeSuccessorParams.js.map +1 -0
- package/dist/modules/attributes/local/successorParams/index.d.ts +6 -0
- package/dist/modules/attributes/local/successorParams/index.d.ts.map +1 -0
- package/dist/modules/attributes/local/successorParams/index.js +22 -0
- package/dist/modules/attributes/local/successorParams/index.js.map +1 -0
- package/dist/modules/notifications/index.d.ts +4 -4
- package/dist/modules/notifications/index.d.ts.map +1 -1
- package/dist/modules/notifications/index.js +4 -4
- package/dist/modules/notifications/index.js.map +1 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ForwardedAttributeDeletedByPeerNotificationItemProcessor.d.ts +14 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ForwardedAttributeDeletedByPeerNotificationItemProcessor.d.ts.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ForwardedAttributeDeletedByPeerNotificationItemProcessor.js +53 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ForwardedAttributeDeletedByPeerNotificationItemProcessor.js.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnAttributeDeletedByOwnerNotificationItemProcessor.d.ts +14 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnAttributeDeletedByOwnerNotificationItemProcessor.d.ts.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnAttributeDeletedByOwnerNotificationItemProcessor.js +59 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnAttributeDeletedByOwnerNotificationItemProcessor.js.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerRelationshipAttributeDeletedByPeerNotificationItemProcessor.d.ts +14 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerRelationshipAttributeDeletedByPeerNotificationItemProcessor.d.ts.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerRelationshipAttributeDeletedByPeerNotificationItemProcessor.js +63 -0
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerRelationshipAttributeDeletedByPeerNotificationItemProcessor.js.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerAttributeSucceededNotificationItemProcessor.d.ts +15 -0
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerAttributeSucceededNotificationItemProcessor.d.ts.map +1 -0
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerAttributeSucceededNotificationItemProcessor.js +102 -0
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerAttributeSucceededNotificationItemProcessor.js.map +1 -0
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.d.ts +2 -2
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js +54 -20
- package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/deleteAttribute/DeleteAttributeRequestItemProcessor.d.ts +4 -2
- package/dist/modules/requests/itemProcessors/deleteAttribute/DeleteAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/deleteAttribute/DeleteAttributeRequestItemProcessor.js +50 -43
- package/dist/modules/requests/itemProcessors/deleteAttribute/DeleteAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.d.ts +2 -2
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js +83 -97
- package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts +2 -2
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js +136 -133
- package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.d.ts +3 -5
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js +94 -90
- package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/transferFileOwnership/TransferFileOwnershipRequestItemProcessor.d.ts +2 -2
- package/dist/modules/requests/itemProcessors/transferFileOwnership/TransferFileOwnershipRequestItemProcessor.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/transferFileOwnership/TransferFileOwnershipRequestItemProcessor.js +7 -11
- package/dist/modules/requests/itemProcessors/transferFileOwnership/TransferFileOwnershipRequestItemProcessor.js.map +1 -1
- package/dist/modules/requests/itemProcessors/utility/createAppropriateResponseItem.d.ts.map +1 -1
- package/dist/modules/requests/itemProcessors/utility/createAppropriateResponseItem.js +31 -53
- package/dist/modules/requests/itemProcessors/utility/createAppropriateResponseItem.js.map +1 -1
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.js +2 -2
- package/dist/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.js.map +1 -1
- package/dist/modules/requests/local/LocalRequest.js +1 -1
- package/dist/modules/requests/local/LocalRequest.js.map +1 -1
- package/dist/modules/requests/local/LocalResponse.js +1 -1
- package/dist/modules/requests/local/LocalResponse.js.map +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts.map +1 -1
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js +17 -16
- package/dist/modules/requests/outgoing/OutgoingRequestsController.js.map +1 -1
- package/package.json +4 -4
- package/dist/modules/attributes/events/AttributeSucceededEventData.d.ts +0 -6
- package/dist/modules/attributes/events/AttributeSucceededEventData.d.ts.map +0 -1
- package/dist/modules/attributes/events/AttributeSucceededEventData.js +0 -3
- package/dist/modules/attributes/events/AttributeSucceededEventData.js.map +0 -1
- package/dist/modules/attributes/events/OwnSharedAttributeDeletedByOwnerEvent.d.ts +0 -7
- package/dist/modules/attributes/events/OwnSharedAttributeDeletedByOwnerEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/OwnSharedAttributeDeletedByOwnerEvent.js +0 -12
- package/dist/modules/attributes/events/OwnSharedAttributeDeletedByOwnerEvent.js.map +0 -1
- package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.d.ts +0 -8
- package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.js +0 -12
- package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.js.map +0 -1
- package/dist/modules/attributes/events/PeerSharedAttributeDeletedByPeerEvent.d.ts +0 -7
- package/dist/modules/attributes/events/PeerSharedAttributeDeletedByPeerEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/PeerSharedAttributeDeletedByPeerEvent.js +0 -12
- package/dist/modules/attributes/events/PeerSharedAttributeDeletedByPeerEvent.js.map +0 -1
- package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.d.ts +0 -8
- package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.js +0 -12
- package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.js.map +0 -1
- package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.d.ts +0 -8
- package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.js +0 -12
- package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.js.map +0 -1
- package/dist/modules/attributes/events/SharedAttributeCopyCreatedEvent.d.ts +0 -7
- package/dist/modules/attributes/events/SharedAttributeCopyCreatedEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/SharedAttributeCopyCreatedEvent.js +0 -12
- package/dist/modules/attributes/events/SharedAttributeCopyCreatedEvent.js.map +0 -1
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeDeletedByPeerEvent.d.ts +0 -7
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeDeletedByPeerEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeDeletedByPeerEvent.js +0 -12
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeDeletedByPeerEvent.js.map +0 -1
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeSucceededEvent.d.ts +0 -8
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeSucceededEvent.d.ts.map +0 -1
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeSucceededEvent.js +0 -12
- package/dist/modules/attributes/events/ThirdPartyRelationshipAttributeSucceededEvent.js.map +0 -1
- package/dist/modules/attributes/local/AttributeSuccessorParams.d.ts +0 -24
- package/dist/modules/attributes/local/AttributeSuccessorParams.d.ts.map +0 -1
- package/dist/modules/attributes/local/AttributeSuccessorParams.js.map +0 -1
- package/dist/modules/attributes/local/CreateAttributeParams.d.ts +0 -15
- package/dist/modules/attributes/local/CreateAttributeParams.d.ts.map +0 -1
- package/dist/modules/attributes/local/CreateAttributeParams.js.map +0 -1
- package/dist/modules/attributes/local/CreateRepositoryAttributeParams.d.ts +0 -20
- package/dist/modules/attributes/local/CreateRepositoryAttributeParams.d.ts.map +0 -1
- package/dist/modules/attributes/local/CreateRepositoryAttributeParams.js.map +0 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.d.ts +0 -22
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.d.ts.map +0 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeCopyParams.js.map +0 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeParams.d.ts +0 -26
- package/dist/modules/attributes/local/CreateSharedLocalAttributeParams.d.ts.map +0 -1
- package/dist/modules/attributes/local/CreateSharedLocalAttributeParams.js.map +0 -1
- package/dist/modules/attributes/local/LocalAttribute.d.ts +0 -112
- package/dist/modules/attributes/local/LocalAttribute.d.ts.map +0 -1
- package/dist/modules/attributes/local/LocalAttribute.js +0 -186
- package/dist/modules/attributes/local/LocalAttribute.js.map +0 -1
- package/dist/modules/attributes/local/LocalAttributeDeletionInfo.d.ts +0 -24
- package/dist/modules/attributes/local/LocalAttributeDeletionInfo.d.ts.map +0 -1
- package/dist/modules/attributes/local/LocalAttributeDeletionInfo.js +0 -42
- package/dist/modules/attributes/local/LocalAttributeDeletionInfo.js.map +0 -1
- package/dist/modules/attributes/local/LocalAttributeShareInfo.d.ts +0 -26
- package/dist/modules/attributes/local/LocalAttributeShareInfo.d.ts.map +0 -1
- package/dist/modules/attributes/local/LocalAttributeShareInfo.js +0 -59
- package/dist/modules/attributes/local/LocalAttributeShareInfo.js.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnSharedAttributeDeletedByOwnerNotificationItemProcessor.d.ts +0 -14
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnSharedAttributeDeletedByOwnerNotificationItemProcessor.d.ts.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnSharedAttributeDeletedByOwnerNotificationItemProcessor.js +0 -56
- package/dist/modules/notifications/itemProcessors/attributeDeleted/OwnSharedAttributeDeletedByOwnerNotificationItemProcessor.js.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerSharedAttributeDeletedByPeerNotificationItemProcessor.d.ts +0 -14
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerSharedAttributeDeletedByPeerNotificationItemProcessor.d.ts.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerSharedAttributeDeletedByPeerNotificationItemProcessor.js +0 -57
- package/dist/modules/notifications/itemProcessors/attributeDeleted/PeerSharedAttributeDeletedByPeerNotificationItemProcessor.js.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor.d.ts +0 -14
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor.d.ts.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor.js +0 -57
- package/dist/modules/notifications/itemProcessors/attributeDeleted/ThirdPartyRelationshipAttributeDeletedByPeerNotificationItemProcessor.js.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerSharedAttributeSucceededNotificationItemProcessor.d.ts +0 -15
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerSharedAttributeSucceededNotificationItemProcessor.d.ts.map +0 -1
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerSharedAttributeSucceededNotificationItemProcessor.js +0 -74
- package/dist/modules/notifications/itemProcessors/attributeSucceeded/PeerSharedAttributeSucceededNotificationItemProcessor.js.map +0 -1
|
@@ -50,21 +50,24 @@ const ConsumptionError_1 = require("../../consumption/ConsumptionError");
|
|
|
50
50
|
const ConsumptionIds_1 = require("../../consumption/ConsumptionIds");
|
|
51
51
|
const common_1 = require("../common");
|
|
52
52
|
const events_1 = require("./events");
|
|
53
|
-
const
|
|
53
|
+
const AttributeForwardingDetails_1 = require("./local/AttributeForwardingDetails");
|
|
54
54
|
const AttributeTagCollection_1 = require("./local/AttributeTagCollection");
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
55
|
+
const LocalAttribute_1 = require("./local/attributeTypes/LocalAttribute");
|
|
56
|
+
const OwnIdentityAttribute_1 = require("./local/attributeTypes/OwnIdentityAttribute");
|
|
57
|
+
const OwnRelationshipAttribute_1 = require("./local/attributeTypes/OwnRelationshipAttribute");
|
|
58
|
+
const PeerIdentityAttribute_1 = require("./local/attributeTypes/PeerIdentityAttribute");
|
|
59
|
+
const PeerRelationshipAttribute_1 = require("./local/attributeTypes/PeerRelationshipAttribute");
|
|
60
|
+
const ThirdPartyRelationshipAttribute_1 = require("./local/attributeTypes/ThirdPartyRelationshipAttribute");
|
|
61
|
+
const deletionInfos_1 = require("./local/deletionInfos");
|
|
61
62
|
const QueryTranslator_1 = require("./local/QueryTranslator");
|
|
63
|
+
const successorParams_1 = require("./local/successorParams");
|
|
64
|
+
const PeerRelationshipAttributeSuccessorParams_1 = require("./local/successorParams/PeerRelationshipAttributeSuccessorParams");
|
|
62
65
|
class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseController {
|
|
63
|
-
constructor(parent, eventBus, identity,
|
|
66
|
+
constructor(parent, eventBus, identity, setDefaultOwnIdentityAttributes) {
|
|
64
67
|
super(ConsumptionControllerName_1.ConsumptionControllerName.AttributesController, parent);
|
|
65
68
|
this.eventBus = eventBus;
|
|
66
69
|
this.identity = identity;
|
|
67
|
-
this.
|
|
70
|
+
this.setDefaultOwnIdentityAttributes = setDefaultOwnIdentityAttributes;
|
|
68
71
|
this.ETAG_DB_KEY = "etag";
|
|
69
72
|
this.CACHE_TIMESTAMP_DB_KEY = "cacheTimestamp";
|
|
70
73
|
this.TAG_COLLECTION_DB_KEY = "tagCollection";
|
|
@@ -72,6 +75,7 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
72
75
|
async init() {
|
|
73
76
|
await super.init();
|
|
74
77
|
this.attributes = await this.parent.accountController.getSynchronizedCollection("Attributes");
|
|
78
|
+
this.forwardingDetails = await this.parent.accountController.getSynchronizedCollection("AttributeForwardingDetails");
|
|
75
79
|
this.tagCollection = await this.parent.accountController.db.getCollection("TagCollection");
|
|
76
80
|
this.attributeTagClient = new transport_1.TagClient(this.parent.transport.config, this.parent.accountController.authenticator, this.parent.transport.correlator);
|
|
77
81
|
const tagDefinitionCacheExists = await this.tagCollection.exists({ name: this.TAG_COLLECTION_DB_KEY });
|
|
@@ -91,18 +95,22 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
91
95
|
});
|
|
92
96
|
if (!result)
|
|
93
97
|
return;
|
|
94
|
-
|
|
98
|
+
const attribute = LocalAttribute_1.LocalAttribute.from(result);
|
|
99
|
+
await this.updateNumberOfForwards(attribute);
|
|
100
|
+
return attribute;
|
|
95
101
|
}
|
|
96
102
|
async getLocalAttributes(query, hideTechnical = false) {
|
|
97
|
-
const enrichedQuery = this.
|
|
103
|
+
const enrichedQuery = this.addHideTechnicalToQuery(query, hideTechnical);
|
|
98
104
|
const attributes = await this.attributes.find(enrichedQuery);
|
|
99
105
|
const parsed = this.parseArray(attributes, LocalAttribute_1.LocalAttribute);
|
|
100
106
|
const sorted = parsed.sort((a, b) => {
|
|
101
107
|
return a.createdAt.compare(b.createdAt);
|
|
102
108
|
});
|
|
109
|
+
for (const attribute of sorted)
|
|
110
|
+
await this.updateNumberOfForwards(attribute);
|
|
103
111
|
return sorted;
|
|
104
112
|
}
|
|
105
|
-
|
|
113
|
+
addHideTechnicalToQuery(query, hideTechnical) {
|
|
106
114
|
if (!hideTechnical)
|
|
107
115
|
return query;
|
|
108
116
|
const hideTechnicalQuery = {
|
|
@@ -129,12 +137,7 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
129
137
|
async executeIQLQuery(query) {
|
|
130
138
|
/* Fetch subset of attributes relevant for IQL queries. We filter for
|
|
131
139
|
* identity attributes which are not shared. */
|
|
132
|
-
const envelopedAttributes = await this.attributes.find({
|
|
133
|
-
"content.@type": "IdentityAttribute",
|
|
134
|
-
shareInfo: {
|
|
135
|
-
$exists: false
|
|
136
|
-
}
|
|
137
|
-
});
|
|
140
|
+
const envelopedAttributes = await this.attributes.find({ "@type": "OwnIdentityAttribute" });
|
|
138
141
|
/* Remove envelope from attributes and execute query. IQL makes no use
|
|
139
142
|
* of the envelope data. */
|
|
140
143
|
const attributes = envelopedAttributes.map((e) => {
|
|
@@ -144,6 +147,8 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
144
147
|
/* Map matched indices back to their respective attributes and return. */
|
|
145
148
|
const matchedAttributes = indices.map((ii) => envelopedAttributes[ii]);
|
|
146
149
|
const result = this.parseArray(matchedAttributes, LocalAttribute_1.LocalAttribute);
|
|
150
|
+
for (const attribute of result)
|
|
151
|
+
await this.updateNumberOfForwards(attribute);
|
|
147
152
|
return result;
|
|
148
153
|
}
|
|
149
154
|
async executeRelationshipAttributeQuery(query) {
|
|
@@ -155,6 +160,8 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
155
160
|
}
|
|
156
161
|
const attributes = await this.attributes.find(dbQuery);
|
|
157
162
|
const attribute = attributes.length > 0 ? LocalAttribute_1.LocalAttribute.from(attributes[0]) : undefined;
|
|
163
|
+
if (attribute)
|
|
164
|
+
await this.updateNumberOfForwards(attribute);
|
|
158
165
|
return attribute;
|
|
159
166
|
}
|
|
160
167
|
async executeThirdPartyRelationshipAttributeQuery(query) {
|
|
@@ -189,73 +196,35 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
189
196
|
const parsedQuery = content_1.IdentityAttributeQuery.from(query);
|
|
190
197
|
const dbQuery = QueryTranslator_1.IdentityAttributeQueryTranslator.translate(parsedQuery);
|
|
191
198
|
dbQuery["content.owner"] = this.identity.address.toString();
|
|
192
|
-
|
|
193
|
-
const attributes =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
value: this.trimAttributeValue(parsedParams.content.value.toJSON())
|
|
207
|
-
};
|
|
208
|
-
parsedParams.content = content_1.IdentityAttribute.from(trimmedAttribute);
|
|
209
|
-
if (!this.validateAttributeCharacters(parsedParams.content)) {
|
|
210
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.forbiddenCharactersInAttribute("The Attribute contains forbidden characters.");
|
|
211
|
-
}
|
|
212
|
-
let localAttribute = LocalAttribute_1.LocalAttribute.from({
|
|
213
|
-
id: parsedParams.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
|
|
199
|
+
const attributeDocs = await this.attributes.find(dbQuery);
|
|
200
|
+
const attributes = this.parseArray(attributeDocs, LocalAttribute_1.LocalAttribute);
|
|
201
|
+
for (const attribute of attributes)
|
|
202
|
+
await this.updateNumberOfForwards(attribute);
|
|
203
|
+
return attributes;
|
|
204
|
+
}
|
|
205
|
+
async createOwnIdentityAttribute(params) {
|
|
206
|
+
const attribute = this.trimAttribute(params.content);
|
|
207
|
+
if (!attribute.owner.equals(this.identity.address)) {
|
|
208
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating an OwnIdentityAttribute, the owner must match the own address.");
|
|
209
|
+
}
|
|
210
|
+
await this.validateAttributeCreation(attribute);
|
|
211
|
+
let ownIdentityAttribute = OwnIdentityAttribute_1.OwnIdentityAttribute.from({
|
|
212
|
+
id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
|
|
214
213
|
createdAt: core_types_1.CoreDate.utc(),
|
|
215
|
-
content:
|
|
216
|
-
parentId: parsedParams.parentId
|
|
214
|
+
content: attribute
|
|
217
215
|
});
|
|
218
|
-
await this.attributes.create(
|
|
219
|
-
if (this.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
async createLocalAttributesForChildrenOfComplexAttribute(localAttribute) {
|
|
229
|
-
if (!(localAttribute.content instanceof content_1.IdentityAttribute)) {
|
|
230
|
-
throw new ConsumptionError_1.ConsumptionError("Only IdentityAttributes may have child Attributes.");
|
|
231
|
-
}
|
|
232
|
-
const childAttributeValues = Object.values(localAttribute.content.value).filter((p) => p instanceof content_1.AbstractAttributeValue);
|
|
233
|
-
for (const propertyValue of childAttributeValues) {
|
|
234
|
-
const childAttribute = content_1.IdentityAttribute.from({
|
|
235
|
-
...localAttribute.content.toJSON(),
|
|
236
|
-
value: propertyValue.toJSON()
|
|
237
|
-
});
|
|
238
|
-
await this.createRepositoryAttribute({
|
|
239
|
-
content: childAttribute,
|
|
240
|
-
parentId: localAttribute.id
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async setAsDefaultRepositoryAttribute(newDefaultAttribute, skipOverwrite) {
|
|
245
|
-
if (!this.setDefaultRepositoryAttributes)
|
|
246
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.setDefaultRepositoryAttributesIsDisabled();
|
|
247
|
-
if (!newDefaultAttribute.isRepositoryAttribute(this.identity.address)) {
|
|
248
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.isNotRepositoryAttribute(newDefaultAttribute.id);
|
|
249
|
-
}
|
|
216
|
+
await this.attributes.create(ownIdentityAttribute);
|
|
217
|
+
if (this.setDefaultOwnIdentityAttributes)
|
|
218
|
+
ownIdentityAttribute = await this.setAsDefaultOwnIdentityAttribute(ownIdentityAttribute, true);
|
|
219
|
+
ownIdentityAttribute.numberOfForwards = 0;
|
|
220
|
+
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), ownIdentityAttribute));
|
|
221
|
+
return ownIdentityAttribute;
|
|
222
|
+
}
|
|
223
|
+
async setAsDefaultOwnIdentityAttribute(newDefaultAttribute, skipOverwrite) {
|
|
224
|
+
if (!this.setDefaultOwnIdentityAttributes)
|
|
225
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.setDefaultOwnIdentityAttributesIsDisabled();
|
|
250
226
|
if (newDefaultAttribute.isDefault)
|
|
251
227
|
return newDefaultAttribute;
|
|
252
|
-
if (newDefaultAttribute.parentId) {
|
|
253
|
-
const parentAttribute = await this.getLocalAttribute(newDefaultAttribute.parentId);
|
|
254
|
-
if (!parentAttribute)
|
|
255
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, newDefaultAttribute.parentId.toString());
|
|
256
|
-
if (parentAttribute.isDefault)
|
|
257
|
-
skipOverwrite = false;
|
|
258
|
-
}
|
|
259
228
|
const valueType = newDefaultAttribute.content.value.constructor.name;
|
|
260
229
|
const query = {
|
|
261
230
|
$and: [
|
|
@@ -267,7 +236,7 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
267
236
|
}
|
|
268
237
|
]
|
|
269
238
|
};
|
|
270
|
-
const currentDefaultAttributeResult = await this.getLocalAttributes(query);
|
|
239
|
+
const currentDefaultAttributeResult = (await this.getLocalAttributes(query));
|
|
271
240
|
if (currentDefaultAttributeResult.length > 1) {
|
|
272
241
|
throw new ConsumptionError_1.ConsumptionError(`There are multiple default Attributes for type ${valueType.toString()}, even though only one is expected.`);
|
|
273
242
|
}
|
|
@@ -283,531 +252,359 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
283
252
|
await this.updateAttributeUnsafe(newDefaultAttribute);
|
|
284
253
|
return newDefaultAttribute;
|
|
285
254
|
}
|
|
286
|
-
async
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const tagValidationResult = await this.validateTagsOfAttribute(parsedParams.content);
|
|
306
|
-
if (tagValidationResult.isError())
|
|
307
|
-
throw tagValidationResult.error;
|
|
308
|
-
const shareInfo = LocalAttributeShareInfo_1.LocalAttributeShareInfo.from({
|
|
255
|
+
async updateAttributeUnsafe(attribute) {
|
|
256
|
+
const doc = await this.attributes.findOne({ [(0, ts_simple_nameof_1.nameof)((c) => c.id)]: attribute.id.toString() });
|
|
257
|
+
if (!doc)
|
|
258
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attribute.id.toString());
|
|
259
|
+
await this.attributes.update(doc, attribute);
|
|
260
|
+
return attribute;
|
|
261
|
+
}
|
|
262
|
+
async createPeerIdentityAttribute(params) {
|
|
263
|
+
const attribute = this.trimAttribute(params.content);
|
|
264
|
+
if (attribute.owner.equals(this.identity.address)) {
|
|
265
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a PeerIdentityAttribute, the owner must not match the own address.");
|
|
266
|
+
}
|
|
267
|
+
if (!attribute.owner.equals(params.peer)) {
|
|
268
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a PeerIdentityAttribute, the owner must match the address of the peer.");
|
|
269
|
+
}
|
|
270
|
+
await this.validateAttributeCreation(attribute);
|
|
271
|
+
const peerIdentityAttribute = PeerIdentityAttribute_1.PeerIdentityAttribute.from({
|
|
272
|
+
id: params.id,
|
|
273
|
+
content: attribute,
|
|
309
274
|
peer: params.peer,
|
|
310
|
-
|
|
311
|
-
thirdPartyAddress: params.thirdPartyAddress
|
|
312
|
-
});
|
|
313
|
-
const peerLocalAttribute = LocalAttribute_1.LocalAttribute.from({
|
|
314
|
-
id: params.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
|
|
315
|
-
content: params.content,
|
|
316
|
-
shareInfo: shareInfo,
|
|
275
|
+
sourceReference: params.sourceReference,
|
|
317
276
|
createdAt: core_types_1.CoreDate.utc()
|
|
318
277
|
});
|
|
319
|
-
await this.attributes.create(
|
|
320
|
-
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(),
|
|
321
|
-
return
|
|
278
|
+
await this.attributes.create(peerIdentityAttribute);
|
|
279
|
+
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), peerIdentityAttribute));
|
|
280
|
+
return peerIdentityAttribute;
|
|
322
281
|
}
|
|
323
|
-
async
|
|
324
|
-
|
|
325
|
-
|
|
282
|
+
async createOwnRelationshipAttribute(params) {
|
|
283
|
+
const attribute = params.content;
|
|
284
|
+
if (!attribute.owner.equals(this.identity.address)) {
|
|
285
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating an OwnRelationshipAttribute, the owner must match the own address.");
|
|
326
286
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
async deleteAttributesExchangedWithPeer(peer) {
|
|
331
|
-
const attributes = await this.getLocalAttributes({ "shareInfo.peer": peer.toString() });
|
|
332
|
-
for (const attribute of attributes) {
|
|
333
|
-
await this.deleteAttributeUnsafe(attribute.id);
|
|
287
|
+
if (params.peer.equals(this.identity.address)) {
|
|
288
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating an OwnRelationshipAttribute, the peer must not match the own address.");
|
|
334
289
|
}
|
|
290
|
+
await this.validateAttributeCreation(attribute);
|
|
291
|
+
const ownRelationshipAttribute = OwnRelationshipAttribute_1.OwnRelationshipAttribute.from({
|
|
292
|
+
id: params.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
|
|
293
|
+
content: attribute,
|
|
294
|
+
peer: params.peer,
|
|
295
|
+
sourceReference: params.sourceReference,
|
|
296
|
+
createdAt: core_types_1.CoreDate.utc()
|
|
297
|
+
});
|
|
298
|
+
await this.attributes.create(ownRelationshipAttribute);
|
|
299
|
+
ownRelationshipAttribute.numberOfForwards = 0;
|
|
300
|
+
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), ownRelationshipAttribute));
|
|
301
|
+
return ownRelationshipAttribute;
|
|
335
302
|
}
|
|
336
|
-
async
|
|
337
|
-
|
|
338
|
-
|
|
303
|
+
async createPeerRelationshipAttribute(params) {
|
|
304
|
+
const attribute = params.content;
|
|
305
|
+
if (attribute.owner.equals(this.identity.address)) {
|
|
306
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a PeerRelationshipAttribute, the owner must not match the own address.");
|
|
339
307
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
await this.deleteAttribute(childAttribute);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
async succeedRepositoryAttribute(predecessorId, successorParams, validate = true) {
|
|
346
|
-
const parsedSuccessorParams = AttributeSuccessorParams_1.AttributeSuccessorParams.from(successorParams);
|
|
347
|
-
const trimmedAttribute = {
|
|
348
|
-
...parsedSuccessorParams.content.toJSON(),
|
|
349
|
-
value: this.trimAttributeValue(parsedSuccessorParams.content.value.toJSON())
|
|
350
|
-
};
|
|
351
|
-
parsedSuccessorParams.content = content_1.IdentityAttribute.from(trimmedAttribute);
|
|
352
|
-
if (validate) {
|
|
353
|
-
const validationResult = await this.validateRepositoryAttributeSuccession(predecessorId, parsedSuccessorParams);
|
|
354
|
-
if (validationResult.isError())
|
|
355
|
-
throw validationResult.error;
|
|
308
|
+
if (!attribute.owner.equals(params.peer)) {
|
|
309
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a PeerRelationshipAttribute, the owner must match the address of the peer.");
|
|
356
310
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
createdAt:
|
|
364
|
-
succeededBy: parsedSuccessorParams.succeededBy
|
|
311
|
+
await this.validateAttributeCreation(attribute);
|
|
312
|
+
const peerRelationshipAttribute = PeerRelationshipAttribute_1.PeerRelationshipAttribute.from({
|
|
313
|
+
id: params.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
|
|
314
|
+
content: attribute,
|
|
315
|
+
peer: params.peer,
|
|
316
|
+
sourceReference: params.sourceReference,
|
|
317
|
+
createdAt: core_types_1.CoreDate.utc()
|
|
365
318
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
319
|
+
await this.attributes.create(peerRelationshipAttribute);
|
|
320
|
+
peerRelationshipAttribute.numberOfForwards = 0;
|
|
321
|
+
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), peerRelationshipAttribute));
|
|
322
|
+
return peerRelationshipAttribute;
|
|
323
|
+
}
|
|
324
|
+
async createThirdPartyRelationshipAttribute(params) {
|
|
325
|
+
const attribute = params.content;
|
|
326
|
+
if (attribute.owner.equals(this.identity.address)) {
|
|
327
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a ThirdPartyRelationshipAttribute, the owner must not match the own address.");
|
|
328
|
+
}
|
|
329
|
+
if (!(attribute.owner.equals(params.peer) || attribute.owner.equals(params.initialAttributePeer))) {
|
|
330
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a ThirdPartyRelationshipAttribute, the owner must match the address of the peer or initial Attribute peer.");
|
|
331
|
+
}
|
|
332
|
+
if (params.peer.equals(params.initialAttributePeer)) {
|
|
333
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongOwnerOfAttribute("When creating a ThirdPartyRelationshipAttribute, the peer must not match the initialAttributePeer.");
|
|
334
|
+
}
|
|
335
|
+
await this.validateAttributeCreation(attribute);
|
|
336
|
+
const thirdPartyRelationshipAttribute = ThirdPartyRelationshipAttribute_1.ThirdPartyRelationshipAttribute.from({
|
|
337
|
+
id: params.id,
|
|
338
|
+
content: attribute,
|
|
339
|
+
peer: params.peer,
|
|
340
|
+
sourceReference: params.sourceReference,
|
|
341
|
+
initialAttributePeer: params.initialAttributePeer,
|
|
342
|
+
createdAt: core_types_1.CoreDate.utc()
|
|
343
|
+
});
|
|
344
|
+
await this.attributes.create(thirdPartyRelationshipAttribute);
|
|
345
|
+
this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), thirdPartyRelationshipAttribute));
|
|
346
|
+
return thirdPartyRelationshipAttribute;
|
|
371
347
|
}
|
|
372
|
-
async
|
|
373
|
-
|
|
348
|
+
async validateAttributeCreation(attribute) {
|
|
349
|
+
if (!this.validateAttributeCharacters(attribute))
|
|
350
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.forbiddenCharactersInAttribute("The Attribute contains forbidden characters.");
|
|
351
|
+
if (attribute instanceof content_1.RelationshipAttribute)
|
|
352
|
+
return;
|
|
353
|
+
const tagValidationResult = await this.validateTagsOfAttribute(attribute);
|
|
354
|
+
if (tagValidationResult.isError())
|
|
355
|
+
throw tagValidationResult.error;
|
|
356
|
+
}
|
|
357
|
+
async addForwardingDetailsToAttribute(attribute, peer, sourceReference) {
|
|
358
|
+
if (await this.isAttributeForwardedToPeer(attribute, peer, true))
|
|
359
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.alreadyForwarded(attribute.id, peer);
|
|
360
|
+
const existingForwardingDetails = await this.getForwardingDetailsForPeer(attribute, peer, true);
|
|
361
|
+
const forwardingDetails = existingForwardingDetails
|
|
362
|
+
? (() => {
|
|
363
|
+
existingForwardingDetails.deletionInfo = undefined;
|
|
364
|
+
return existingForwardingDetails;
|
|
365
|
+
})()
|
|
366
|
+
: AttributeForwardingDetails_1.AttributeForwardingDetails.from({
|
|
367
|
+
id: await ConsumptionIds_1.ConsumptionIds.attributeForwardingDetails.generate(),
|
|
368
|
+
attributeId: attribute.id,
|
|
369
|
+
peer,
|
|
370
|
+
sourceReference,
|
|
371
|
+
sharedAt: core_types_1.CoreDate.utc()
|
|
372
|
+
});
|
|
373
|
+
await this.upsertForwardingDetailsForPeer(attribute, peer, forwardingDetails);
|
|
374
|
+
this.eventBus.publish(new events_1.AttributeForwardingDetailsChangedEvent(this.identity.address.toString(), attribute));
|
|
375
|
+
return attribute;
|
|
376
|
+
}
|
|
377
|
+
async succeedOwnIdentityAttribute(predecessor, successorParams, validate = true) {
|
|
378
|
+
const parsedSuccessorParams = successorParams_1.OwnIdentityAttributeSuccessorParams.from(successorParams);
|
|
379
|
+
const attribute = this.trimAttribute(parsedSuccessorParams.content);
|
|
374
380
|
if (validate) {
|
|
375
|
-
const validationResult = await this.
|
|
381
|
+
const validationResult = await this.validateOwnIdentityAttributeSuccession(predecessor, parsedSuccessorParams);
|
|
376
382
|
if (validationResult.isError())
|
|
377
383
|
throw validationResult.error;
|
|
378
384
|
}
|
|
379
|
-
const
|
|
380
|
-
id:
|
|
381
|
-
content:
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
createdAt: parsedSuccessorParams.createdAt,
|
|
386
|
-
succeededBy: parsedSuccessorParams.succeededBy
|
|
385
|
+
const successor = OwnIdentityAttribute_1.OwnIdentityAttribute.from({
|
|
386
|
+
id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
|
|
387
|
+
content: attribute,
|
|
388
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
389
|
+
succeeds: predecessor.id,
|
|
390
|
+
isDefault: predecessor.isDefault
|
|
387
391
|
});
|
|
388
|
-
|
|
392
|
+
await this.succeedAttributeUnsafe(predecessor, successor);
|
|
393
|
+
await this.removeDefault(predecessor);
|
|
394
|
+
successor.numberOfForwards = 0;
|
|
395
|
+
this.eventBus.publish(new events_1.AttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
|
|
389
396
|
return { predecessor, successor };
|
|
390
397
|
}
|
|
391
|
-
async
|
|
392
|
-
|
|
398
|
+
async succeedAttributeUnsafe(predecessor, successor) {
|
|
399
|
+
await this.attributes.create(successor);
|
|
400
|
+
predecessor.succeededBy = successor.id;
|
|
401
|
+
await this.updateAttributeUnsafe(predecessor);
|
|
402
|
+
}
|
|
403
|
+
async removeDefault(attribute) {
|
|
404
|
+
if (!attribute.isDefault)
|
|
405
|
+
return attribute;
|
|
406
|
+
attribute.isDefault = undefined;
|
|
407
|
+
await this.updateAttributeUnsafe(attribute);
|
|
408
|
+
return attribute;
|
|
409
|
+
}
|
|
410
|
+
async succeedPeerIdentityAttribute(predecessor, successorParams, validate = true) {
|
|
411
|
+
const parsedSuccessorParams = successorParams_1.PeerIdentityAttributeSuccessorParams.from(successorParams);
|
|
412
|
+
const attribute = this.trimAttribute(parsedSuccessorParams.content);
|
|
393
413
|
if (validate) {
|
|
394
|
-
const validationResult = await this.
|
|
414
|
+
const validationResult = await this.validatePeerIdentityAttributeSuccession(predecessor, parsedSuccessorParams);
|
|
395
415
|
if (validationResult.isError())
|
|
396
416
|
throw validationResult.error;
|
|
397
417
|
}
|
|
398
|
-
const
|
|
418
|
+
const successor = PeerIdentityAttribute_1.PeerIdentityAttribute.from({
|
|
399
419
|
id: parsedSuccessorParams.id,
|
|
400
|
-
content:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
succeededBy: parsedSuccessorParams.succeededBy
|
|
420
|
+
content: attribute,
|
|
421
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
422
|
+
succeeds: predecessor.id,
|
|
423
|
+
peer: predecessor.peer,
|
|
424
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
406
425
|
});
|
|
407
|
-
|
|
426
|
+
await this.succeedAttributeUnsafe(predecessor, successor);
|
|
408
427
|
return { predecessor, successor };
|
|
409
428
|
}
|
|
410
|
-
async
|
|
411
|
-
const parsedSuccessorParams =
|
|
429
|
+
async succeedOwnRelationshipAttribute(predecessor, successorParams, validate = true) {
|
|
430
|
+
const parsedSuccessorParams = successorParams_1.OwnRelationshipAttributeSuccessorParams.from(successorParams);
|
|
412
431
|
if (validate) {
|
|
413
|
-
const validationResult = await this.
|
|
432
|
+
const validationResult = await this.validateOwnRelationshipAttributeSuccession(predecessor, parsedSuccessorParams);
|
|
414
433
|
if (validationResult.isError())
|
|
415
434
|
throw validationResult.error;
|
|
416
435
|
}
|
|
417
|
-
const
|
|
418
|
-
id:
|
|
436
|
+
const successor = OwnRelationshipAttribute_1.OwnRelationshipAttribute.from({
|
|
437
|
+
id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
|
|
419
438
|
content: parsedSuccessorParams.content,
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
succeededBy: parsedSuccessorParams.succeededBy
|
|
439
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
440
|
+
succeeds: predecessor.id,
|
|
441
|
+
peer: predecessor.peer,
|
|
442
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
425
443
|
});
|
|
426
|
-
|
|
444
|
+
await this.succeedAttributeUnsafe(predecessor, successor);
|
|
445
|
+
successor.numberOfForwards = 0;
|
|
446
|
+
this.eventBus.publish(new events_1.AttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
|
|
427
447
|
return { predecessor, successor };
|
|
428
448
|
}
|
|
429
|
-
async
|
|
430
|
-
const parsedSuccessorParams =
|
|
449
|
+
async succeedPeerRelationshipAttribute(predecessor, successorParams, validate = true) {
|
|
450
|
+
const parsedSuccessorParams = PeerRelationshipAttributeSuccessorParams_1.PeerRelationshipAttributeSuccessorParams.from(successorParams);
|
|
431
451
|
if (validate) {
|
|
432
|
-
const validationResult = await this.
|
|
452
|
+
const validationResult = await this.validatePeerRelationshipAttributeSuccession(predecessor, parsedSuccessorParams);
|
|
433
453
|
if (validationResult.isError())
|
|
434
454
|
throw validationResult.error;
|
|
435
455
|
}
|
|
436
|
-
const
|
|
456
|
+
const successor = PeerRelationshipAttribute_1.PeerRelationshipAttribute.from({
|
|
437
457
|
id: parsedSuccessorParams.id,
|
|
438
458
|
content: parsedSuccessorParams.content,
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
succeededBy: parsedSuccessorParams.succeededBy
|
|
459
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
460
|
+
succeeds: predecessor.id,
|
|
461
|
+
peer: predecessor.peer,
|
|
462
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
444
463
|
});
|
|
445
|
-
|
|
464
|
+
await this.succeedAttributeUnsafe(predecessor, successor);
|
|
465
|
+
successor.numberOfForwards = 0;
|
|
446
466
|
return { predecessor, successor };
|
|
447
467
|
}
|
|
448
|
-
async succeedThirdPartyRelationshipAttribute(
|
|
449
|
-
const parsedSuccessorParams =
|
|
468
|
+
async succeedThirdPartyRelationshipAttribute(predecessor, successorParams, validate = true) {
|
|
469
|
+
const parsedSuccessorParams = successorParams_1.ThirdPartyRelationshipAttributeSuccessorParams.from(successorParams);
|
|
450
470
|
if (validate) {
|
|
451
|
-
const validationResult = await this.validateThirdPartyRelationshipAttributeSuccession(
|
|
452
|
-
if (validationResult.isError())
|
|
471
|
+
const validationResult = await this.validateThirdPartyRelationshipAttributeSuccession(predecessor, parsedSuccessorParams);
|
|
472
|
+
if (validationResult.isError())
|
|
453
473
|
throw validationResult.error;
|
|
454
|
-
}
|
|
455
474
|
}
|
|
456
|
-
const
|
|
475
|
+
const successor = ThirdPartyRelationshipAttribute_1.ThirdPartyRelationshipAttribute.from({
|
|
457
476
|
id: parsedSuccessorParams.id,
|
|
458
477
|
content: parsedSuccessorParams.content,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
});
|
|
465
|
-
this.eventBus.publish(new events_1.ThirdPartyRelationshipAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
|
|
466
|
-
return { predecessor, successor };
|
|
467
|
-
}
|
|
468
|
-
async succeedChildrenOfComplexAttribute(parentSuccessorId) {
|
|
469
|
-
const parentSuccessor = await this.getLocalAttribute(parentSuccessorId);
|
|
470
|
-
if (!parentSuccessor)
|
|
471
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.invalidParentSuccessor(parentSuccessorId);
|
|
472
|
-
const childAttributeValues = Object.values(parentSuccessor.content.value).filter((elem) => elem instanceof content_1.AbstractAttributeValue);
|
|
473
|
-
for (const childAttributeValue of childAttributeValues) {
|
|
474
|
-
let currentParent = await this.getLocalAttribute(parentSuccessorId);
|
|
475
|
-
let child;
|
|
476
|
-
while (!child && currentParent?.succeeds) {
|
|
477
|
-
const currentPredecessor = (await this.getLocalAttribute(currentParent.succeeds));
|
|
478
|
-
currentParent = currentPredecessor;
|
|
479
|
-
child = await this.getChildAttributesByValueType(currentParent.id, childAttributeValue.constructor);
|
|
480
|
-
}
|
|
481
|
-
const childPredecessorId = child?.id;
|
|
482
|
-
if (childPredecessorId) {
|
|
483
|
-
await this._succeedAttributeUnsafe(childPredecessorId, {
|
|
484
|
-
content: content_1.IdentityAttribute.from({
|
|
485
|
-
value: childAttributeValue.toJSON(),
|
|
486
|
-
owner: this.identity.address
|
|
487
|
-
}),
|
|
488
|
-
parentId: parentSuccessorId,
|
|
489
|
-
createdAt: parentSuccessor.createdAt
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
await this.createAttributeUnsafe({
|
|
494
|
-
content: content_1.IdentityAttribute.from({
|
|
495
|
-
value: childAttributeValue.toJSON(),
|
|
496
|
-
owner: this.identity.address
|
|
497
|
-
}),
|
|
498
|
-
parentId: parentSuccessorId,
|
|
499
|
-
createdAt: parentSuccessor.createdAt
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
async getChildAttributesByValueType(parentId, valueType) {
|
|
505
|
-
const children = await this.getLocalAttributes({
|
|
506
|
-
parentId: parentId.toString()
|
|
507
|
-
});
|
|
508
|
-
/** We currently assume that all of the child attributes of a complex
|
|
509
|
-
* attribute have distinct types. */
|
|
510
|
-
return children.find((elem) => elem.content.value instanceof valueType);
|
|
511
|
-
}
|
|
512
|
-
async _succeedAttributeUnsafe(predecessorId, successorParams) {
|
|
513
|
-
const predecessor = await this.getLocalAttribute(predecessorId);
|
|
514
|
-
if (!predecessor)
|
|
515
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorDoesNotExist();
|
|
516
|
-
const successor = await this.createAttributeUnsafe({
|
|
517
|
-
id: successorParams.id,
|
|
518
|
-
content: successorParams.content,
|
|
519
|
-
succeeds: predecessorId,
|
|
520
|
-
shareInfo: successorParams.shareInfo,
|
|
521
|
-
parentId: successorParams.parentId,
|
|
522
|
-
createdAt: successorParams.createdAt,
|
|
523
|
-
succeededBy: successorParams.succeededBy,
|
|
524
|
-
isDefault: predecessor.isDefault
|
|
478
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
479
|
+
succeeds: predecessor.id,
|
|
480
|
+
peer: predecessor.peer,
|
|
481
|
+
sourceReference: parsedSuccessorParams.sourceReference,
|
|
482
|
+
initialAttributePeer: predecessor.initialAttributePeer
|
|
525
483
|
});
|
|
526
|
-
await this.
|
|
527
|
-
|
|
528
|
-
await this.updateAttributeUnsafe(predecessor);
|
|
484
|
+
await this.succeedAttributeUnsafe(predecessor, successor);
|
|
485
|
+
this.eventBus.publish(new events_1.AttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
|
|
529
486
|
return { predecessor, successor };
|
|
530
487
|
}
|
|
531
|
-
async
|
|
532
|
-
if (!attribute.isDefault)
|
|
533
|
-
return attribute;
|
|
534
|
-
attribute.isDefault = undefined;
|
|
535
|
-
await this.updateAttributeUnsafe(attribute);
|
|
536
|
-
return attribute;
|
|
537
|
-
}
|
|
538
|
-
async validateRepositoryAttributeSuccession(predecessorId, successorParams) {
|
|
488
|
+
async validateOwnIdentityAttributeSuccession(predecessor, successorParams) {
|
|
539
489
|
let parsedSuccessorParams;
|
|
540
490
|
try {
|
|
541
|
-
parsedSuccessorParams =
|
|
491
|
+
parsedSuccessorParams = successorParams_1.OwnIdentityAttributeSuccessorParams.from(successorParams);
|
|
542
492
|
}
|
|
543
493
|
catch (e) {
|
|
544
494
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
545
495
|
}
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
496
|
+
const tagValidationResult = await this.validateTagsOfAttribute(parsedSuccessorParams.content);
|
|
497
|
+
if (tagValidationResult.isError())
|
|
498
|
+
throw tagValidationResult.error;
|
|
499
|
+
const successor = OwnIdentityAttribute_1.OwnIdentityAttribute.from({
|
|
500
|
+
id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
|
|
552
501
|
content: parsedSuccessorParams.content,
|
|
553
|
-
createdAt:
|
|
554
|
-
succeeds:
|
|
555
|
-
succeededBy: parsedSuccessorParams.succeededBy,
|
|
556
|
-
shareInfo: parsedSuccessorParams.shareInfo,
|
|
557
|
-
parentId: parsedSuccessorParams.parentId
|
|
502
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
503
|
+
succeeds: predecessor.id
|
|
558
504
|
});
|
|
559
|
-
|
|
560
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorIsNotRepositoryAttribute());
|
|
561
|
-
}
|
|
562
|
-
if (!successor.isRepositoryAttribute(this.identity.address)) {
|
|
563
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotRepositoryAttribute());
|
|
564
|
-
}
|
|
565
|
-
return common_1.ValidationResult.success();
|
|
505
|
+
return await this.validateAttributeSuccession(predecessor, successor);
|
|
566
506
|
}
|
|
567
|
-
async
|
|
507
|
+
async validatePeerIdentityAttributeSuccession(predecessor, successorParams) {
|
|
568
508
|
let parsedSuccessorParams;
|
|
569
509
|
try {
|
|
570
|
-
parsedSuccessorParams =
|
|
510
|
+
parsedSuccessorParams = successorParams_1.PeerIdentityAttributeSuccessorParams.from(successorParams);
|
|
571
511
|
}
|
|
572
512
|
catch (e) {
|
|
573
513
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
574
514
|
}
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
return commonValidation;
|
|
578
|
-
const predecessor = (await this.getLocalAttribute(predecessorId));
|
|
579
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
580
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
515
|
+
const successor = PeerIdentityAttribute_1.PeerIdentityAttribute.from({
|
|
516
|
+
id: parsedSuccessorParams.id,
|
|
581
517
|
content: parsedSuccessorParams.content,
|
|
582
|
-
createdAt:
|
|
583
|
-
succeeds:
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
parentId: parsedSuccessorParams.parentId
|
|
518
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
519
|
+
succeeds: predecessor.id,
|
|
520
|
+
peer: predecessor.peer,
|
|
521
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
587
522
|
});
|
|
588
|
-
if (
|
|
589
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.
|
|
590
|
-
}
|
|
591
|
-
if (!successor.isOwnSharedIdentityAttribute(this.identity.address)) {
|
|
592
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotOwnSharedIdentityAttribute());
|
|
593
|
-
}
|
|
594
|
-
if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
|
|
595
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangePeer());
|
|
596
|
-
}
|
|
597
|
-
if (!successor.shareInfo.sourceAttribute) {
|
|
598
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorSourceAttributeIsNotSpecified());
|
|
523
|
+
if (predecessor.deletionInfo?.deletionStatus === deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter) {
|
|
524
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedSharedAttributesDeletedByPeer());
|
|
599
525
|
}
|
|
600
|
-
|
|
601
|
-
if (!successorSource) {
|
|
602
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorSourceAttributeDoesNotExist());
|
|
603
|
-
}
|
|
604
|
-
if (!successorSource.isRepositoryAttribute(this.identity.address)) {
|
|
605
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorSourceAttributeIsNotRepositoryAttribute());
|
|
606
|
-
}
|
|
607
|
-
if (!lodash_1.default.isEqual(successorSource.content.toJSON(), successor.content.toJSON())) {
|
|
608
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorSourceContentIsNotEqualToCopyContent());
|
|
609
|
-
}
|
|
610
|
-
const predecessorSource = predecessor.shareInfo.sourceAttribute ? await this.getLocalAttribute(predecessor.shareInfo.sourceAttribute) : undefined;
|
|
611
|
-
if (predecessorSource) {
|
|
612
|
-
if (!predecessorSource.isRepositoryAttribute(this.identity.address)) {
|
|
613
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorSourceAttributeIsNotRepositoryAttribute());
|
|
614
|
-
}
|
|
615
|
-
const successorSourceVersionIds = (await this.getVersionsOfAttribute(successorSource.id)).map((x) => x.id.toString());
|
|
616
|
-
if (!predecessorSource.succeededBy || !successorSourceVersionIds.some((id) => id === predecessorSource.succeededBy?.toString())) {
|
|
617
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorSourceDoesNotSucceedPredecessorSource());
|
|
618
|
-
}
|
|
619
|
-
if (!lodash_1.default.isEqual(predecessorSource.content.toJSON(), predecessor.content.toJSON())) {
|
|
620
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorSourceContentIsNotEqualToCopyContent());
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
return common_1.ValidationResult.success();
|
|
526
|
+
return await this.validateAttributeSuccession(predecessor, successor);
|
|
624
527
|
}
|
|
625
|
-
async
|
|
528
|
+
async validateOwnRelationshipAttributeSuccession(predecessor, successorParams) {
|
|
626
529
|
let parsedSuccessorParams;
|
|
627
530
|
try {
|
|
628
|
-
parsedSuccessorParams =
|
|
531
|
+
parsedSuccessorParams = successorParams_1.OwnRelationshipAttributeSuccessorParams.from(successorParams);
|
|
629
532
|
}
|
|
630
533
|
catch (e) {
|
|
631
534
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
632
535
|
}
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
return commonValidation;
|
|
636
|
-
const predecessor = (await this.getLocalAttribute(predecessorId));
|
|
637
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
638
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
536
|
+
const successor = OwnRelationshipAttribute_1.OwnRelationshipAttribute.from({
|
|
537
|
+
id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
|
|
639
538
|
content: parsedSuccessorParams.content,
|
|
640
|
-
createdAt:
|
|
641
|
-
succeeds:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
parentId: parsedSuccessorParams.parentId
|
|
539
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
540
|
+
succeeds: predecessor.id,
|
|
541
|
+
peer: predecessor.peer,
|
|
542
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
645
543
|
});
|
|
646
|
-
if (
|
|
647
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorIsNotOwnSharedRelationshipAttribute());
|
|
648
|
-
}
|
|
649
|
-
if (!successor.isOwnSharedRelationshipAttribute(this.identity.address)) {
|
|
650
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotOwnSharedRelationshipAttribute());
|
|
651
|
-
}
|
|
652
|
-
if (successor.content.key !== predecessor.content.key) {
|
|
544
|
+
if (predecessor.content.key !== successor.content.key) {
|
|
653
545
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangeKey());
|
|
654
546
|
}
|
|
655
|
-
if (
|
|
656
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.
|
|
657
|
-
}
|
|
658
|
-
return common_1.ValidationResult.success();
|
|
659
|
-
}
|
|
660
|
-
async validatePeerSharedIdentityAttributeSuccession(predecessorId, successorParams) {
|
|
661
|
-
let parsedSuccessorParams;
|
|
662
|
-
try {
|
|
663
|
-
parsedSuccessorParams = AttributeSuccessorParams_1.AttributeSuccessorParams.from(successorParams);
|
|
664
|
-
}
|
|
665
|
-
catch (e) {
|
|
666
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
667
|
-
}
|
|
668
|
-
const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, parsedSuccessorParams);
|
|
669
|
-
if (commonValidation.isError())
|
|
670
|
-
return commonValidation;
|
|
671
|
-
const predecessor = (await this.getLocalAttribute(predecessorId));
|
|
672
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
673
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
674
|
-
content: parsedSuccessorParams.content,
|
|
675
|
-
createdAt: parsedSuccessorParams.createdAt ?? core_types_1.CoreDate.utc(),
|
|
676
|
-
succeeds: parsedSuccessorParams.succeeds,
|
|
677
|
-
succeededBy: parsedSuccessorParams.succeededBy,
|
|
678
|
-
shareInfo: parsedSuccessorParams.shareInfo,
|
|
679
|
-
parentId: parsedSuccessorParams.parentId
|
|
680
|
-
});
|
|
681
|
-
if (!predecessor.isPeerSharedIdentityAttribute()) {
|
|
682
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorIsNotPeerSharedIdentityAttribute());
|
|
547
|
+
if (predecessor.deletionInfo?.deletionStatus === deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient) {
|
|
548
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedSharedAttributesDeletedByPeer());
|
|
683
549
|
}
|
|
684
|
-
|
|
685
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotPeerSharedIdentityAttribute());
|
|
686
|
-
}
|
|
687
|
-
if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
|
|
688
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangePeer());
|
|
689
|
-
}
|
|
690
|
-
return common_1.ValidationResult.success();
|
|
550
|
+
return await this.validateAttributeSuccession(predecessor, successor);
|
|
691
551
|
}
|
|
692
|
-
async
|
|
552
|
+
async validatePeerRelationshipAttributeSuccession(predecessor, successorParams) {
|
|
693
553
|
let parsedSuccessorParams;
|
|
694
554
|
try {
|
|
695
|
-
parsedSuccessorParams =
|
|
555
|
+
parsedSuccessorParams = PeerRelationshipAttributeSuccessorParams_1.PeerRelationshipAttributeSuccessorParams.from(successorParams);
|
|
696
556
|
}
|
|
697
557
|
catch (e) {
|
|
698
558
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
699
559
|
}
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
return commonValidation;
|
|
703
|
-
const predecessor = (await this.getLocalAttribute(predecessorId));
|
|
704
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
705
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
560
|
+
const successor = PeerRelationshipAttribute_1.PeerRelationshipAttribute.from({
|
|
561
|
+
id: parsedSuccessorParams.id,
|
|
706
562
|
content: parsedSuccessorParams.content,
|
|
707
|
-
createdAt:
|
|
708
|
-
succeeds:
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
parentId: parsedSuccessorParams.parentId
|
|
563
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
564
|
+
succeeds: predecessor.id,
|
|
565
|
+
peer: predecessor.peer,
|
|
566
|
+
sourceReference: parsedSuccessorParams.sourceReference
|
|
712
567
|
});
|
|
713
|
-
if (
|
|
714
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorIsNotPeerSharedRelationshipAttribute());
|
|
715
|
-
}
|
|
716
|
-
if (!successor.isPeerSharedRelationshipAttribute()) {
|
|
717
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotPeerSharedRelationshipAttribute());
|
|
718
|
-
}
|
|
719
|
-
if (successor.content.key !== predecessor.content.key) {
|
|
568
|
+
if (predecessor.content.key !== successor.content.key) {
|
|
720
569
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangeKey());
|
|
721
570
|
}
|
|
722
|
-
if (
|
|
723
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.
|
|
571
|
+
if (predecessor.deletionInfo?.deletionStatus === deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter) {
|
|
572
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedSharedAttributesDeletedByPeer());
|
|
724
573
|
}
|
|
725
|
-
return
|
|
574
|
+
return await this.validateAttributeSuccession(predecessor, successor);
|
|
726
575
|
}
|
|
727
|
-
async validateThirdPartyRelationshipAttributeSuccession(
|
|
576
|
+
async validateThirdPartyRelationshipAttributeSuccession(predecessor, successorParams) {
|
|
728
577
|
let parsedSuccessorParams;
|
|
729
578
|
try {
|
|
730
|
-
parsedSuccessorParams =
|
|
579
|
+
parsedSuccessorParams = successorParams_1.ThirdPartyRelationshipAttributeSuccessorParams.from(successorParams);
|
|
731
580
|
}
|
|
732
581
|
catch (e) {
|
|
733
582
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
734
583
|
}
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
return commonValidation;
|
|
738
|
-
const predecessor = (await this.getLocalAttribute(predecessorId));
|
|
739
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
740
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
584
|
+
const successor = ThirdPartyRelationshipAttribute_1.ThirdPartyRelationshipAttribute.from({
|
|
585
|
+
id: parsedSuccessorParams.id,
|
|
741
586
|
content: parsedSuccessorParams.content,
|
|
742
|
-
createdAt:
|
|
743
|
-
succeeds:
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
587
|
+
createdAt: core_types_1.CoreDate.utc(),
|
|
588
|
+
succeeds: predecessor.id,
|
|
589
|
+
peer: predecessor.peer,
|
|
590
|
+
sourceReference: parsedSuccessorParams.sourceReference,
|
|
591
|
+
initialAttributePeer: predecessor.initialAttributePeer
|
|
747
592
|
});
|
|
748
|
-
if (
|
|
749
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorIsNotThirdPartyRelationshipAttribute());
|
|
750
|
-
}
|
|
751
|
-
if (!successor.isThirdPartyRelationshipAttribute()) {
|
|
752
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotThirdPartyRelationshipAttribute());
|
|
753
|
-
}
|
|
754
|
-
if (successor.content.key !== predecessor.content.key) {
|
|
593
|
+
if (predecessor.content.key !== successor.content.key) {
|
|
755
594
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangeKey());
|
|
756
595
|
}
|
|
757
|
-
if (
|
|
758
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.
|
|
759
|
-
}
|
|
760
|
-
if (!predecessor.shareInfo.thirdPartyAddress.equals(successor.shareInfo.thirdPartyAddress)) {
|
|
761
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangeThirdParty());
|
|
596
|
+
if (predecessor.deletionInfo?.deletionStatus === deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter) {
|
|
597
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedSharedAttributesDeletedByPeer());
|
|
762
598
|
}
|
|
763
|
-
return
|
|
599
|
+
return await this.validateAttributeSuccession(predecessor, successor);
|
|
764
600
|
}
|
|
765
|
-
async
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}
|
|
770
|
-
catch (e) {
|
|
771
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorIsNotAValidAttribute(e));
|
|
772
|
-
}
|
|
773
|
-
const tagValidationResult = await this.validateTagsOfAttribute(parsedSuccessorParams.content);
|
|
774
|
-
if (tagValidationResult.isError())
|
|
775
|
-
throw tagValidationResult.error;
|
|
776
|
-
const successor = LocalAttribute_1.LocalAttribute.from({
|
|
777
|
-
id: core_types_1.CoreId.from(parsedSuccessorParams.id ?? "dummy"),
|
|
778
|
-
content: parsedSuccessorParams.content,
|
|
779
|
-
createdAt: parsedSuccessorParams.createdAt ?? core_types_1.CoreDate.utc(),
|
|
780
|
-
succeeds: parsedSuccessorParams.succeeds,
|
|
781
|
-
succeededBy: parsedSuccessorParams.succeededBy,
|
|
782
|
-
shareInfo: parsedSuccessorParams.shareInfo,
|
|
783
|
-
parentId: parsedSuccessorParams.parentId
|
|
784
|
-
});
|
|
785
|
-
if (parsedSuccessorParams.id) {
|
|
786
|
-
const successor = await this.getLocalAttribute(core_types_1.CoreId.from(parsedSuccessorParams.id));
|
|
787
|
-
if (successor)
|
|
788
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorMustNotYetExist());
|
|
789
|
-
}
|
|
790
|
-
if (successor.succeededBy) {
|
|
791
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorMustNotHaveASuccessor());
|
|
792
|
-
}
|
|
793
|
-
if (successor.parentId) {
|
|
794
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedChildOfComplexAttribute(predecessorId.toString()));
|
|
795
|
-
}
|
|
796
|
-
const predecessor = await this.getLocalAttribute(predecessorId);
|
|
797
|
-
if (!predecessor) {
|
|
798
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.predecessorDoesNotExist());
|
|
799
|
-
}
|
|
601
|
+
async validateAttributeSuccession(predecessor, successor) {
|
|
602
|
+
const existingAttributeWithSameId = await this.getLocalAttribute(successor.id);
|
|
603
|
+
if (existingAttributeWithSameId)
|
|
604
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorMustNotYetExist());
|
|
800
605
|
if (predecessor.succeededBy) {
|
|
801
606
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedAttributesWithASuccessor(predecessor.succeededBy.toString()));
|
|
802
607
|
}
|
|
803
|
-
if (predecessor.parentId) {
|
|
804
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedChildOfComplexAttribute(predecessorId.toString()));
|
|
805
|
-
}
|
|
806
|
-
if (predecessor.hasDeletionInfo() &&
|
|
807
|
-
!(predecessor.deletionInfo.deletionStatus === LocalAttributeDeletionInfo_1.LocalAttributeDeletionStatus.DeletionRequestRejected ||
|
|
808
|
-
predecessor.deletionInfo.deletionStatus === LocalAttributeDeletionInfo_1.LocalAttributeDeletionStatus.DeletionRequestSent)) {
|
|
809
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSucceedAttributesWithDeletionInfo());
|
|
810
|
-
}
|
|
811
608
|
if (lodash_1.default.isEqual(successor.content.toJSON(), predecessor.content.toJSON())) {
|
|
812
609
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustChangeContent());
|
|
813
610
|
}
|
|
@@ -820,120 +617,66 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
820
617
|
if (predecessor.content.value.constructor !== successor.content.value.constructor) {
|
|
821
618
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successionMustNotChangeValueType());
|
|
822
619
|
}
|
|
823
|
-
if (successor.succeeds && !predecessorId.equals(successor.succeeds.toString())) {
|
|
824
|
-
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.setPredecessorIdDoesNotMatchActualPredecessorId());
|
|
825
|
-
}
|
|
826
620
|
if (!this.validateAttributeCharacters(successor.content)) {
|
|
827
621
|
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.forbiddenCharactersInAttribute("The successor contains forbidden characters."));
|
|
828
622
|
}
|
|
829
623
|
return common_1.ValidationResult.success();
|
|
830
624
|
}
|
|
831
|
-
async
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
parentId: attributeData.parentId,
|
|
838
|
-
succeededBy: attributeData.succeededBy,
|
|
839
|
-
succeeds: attributeData.succeeds,
|
|
840
|
-
deletionInfo: attributeData.deletionInfo,
|
|
841
|
-
isDefault: attributeData.isDefault
|
|
842
|
-
});
|
|
843
|
-
await this.attributes.create(localAttribute);
|
|
844
|
-
return localAttribute;
|
|
845
|
-
}
|
|
846
|
-
async updateAttributeUnsafe(attributeParams) {
|
|
847
|
-
const doc = await this.attributes.findOne({
|
|
848
|
-
[(0, ts_simple_nameof_1.nameof)((c) => c.id)]: attributeParams.id.toString()
|
|
849
|
-
});
|
|
850
|
-
if (!doc) {
|
|
851
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attributeParams.id.toString());
|
|
852
|
-
}
|
|
853
|
-
const params = {
|
|
854
|
-
id: attributeParams.id,
|
|
855
|
-
content: attributeParams.content,
|
|
856
|
-
createdAt: attributeParams.createdAt,
|
|
857
|
-
parentId: attributeParams.parentId,
|
|
858
|
-
shareInfo: attributeParams.shareInfo,
|
|
859
|
-
succeededBy: attributeParams.succeededBy,
|
|
860
|
-
succeeds: attributeParams.succeeds,
|
|
861
|
-
deletionInfo: attributeParams.deletionInfo,
|
|
862
|
-
isDefault: attributeParams.isDefault
|
|
863
|
-
};
|
|
864
|
-
const newAttribute = LocalAttribute_1.LocalAttribute.from(params);
|
|
865
|
-
await this.attributes.update(doc, newAttribute);
|
|
866
|
-
return newAttribute;
|
|
625
|
+
async deleteAttribute(attributeId) {
|
|
626
|
+
const attribute = await this.getLocalAttribute(attributeId);
|
|
627
|
+
if (!attribute)
|
|
628
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attributeId.toString());
|
|
629
|
+
await this.deleteAttributeUnsafe(attributeId);
|
|
630
|
+
this.eventBus.publish(new events_1.AttributeDeletedEvent(this.identity.address.toString(), attribute));
|
|
867
631
|
}
|
|
868
632
|
async deleteAttributeUnsafe(id) {
|
|
869
633
|
await this.attributes.delete({ id: id });
|
|
870
634
|
}
|
|
871
|
-
async
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
const childAttributes = await this.getLocalAttributes({ parentId: attribute.id.toString() });
|
|
876
|
-
const parentAndChildAttributes = [attribute, ...childAttributes];
|
|
877
|
-
for (const attr of parentAndChildAttributes) {
|
|
878
|
-
if (attr.succeededBy) {
|
|
879
|
-
const successor = await this.getLocalAttribute(attr.succeededBy);
|
|
880
|
-
if (!successor) {
|
|
881
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorDoesNotExist();
|
|
882
|
-
}
|
|
883
|
-
await this.detachSuccessor(successor);
|
|
884
|
-
}
|
|
635
|
+
async deleteAttributesExchangedWithPeer(peer) {
|
|
636
|
+
const receivedAttributes = await this.getLocalAttributes({ peer: peer.toString() });
|
|
637
|
+
for (const attribute of receivedAttributes) {
|
|
638
|
+
await this.deleteAttributeUnsafe(attribute.id);
|
|
885
639
|
}
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
});
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
const predecessorCopies = await this.getSharedPredecessorsOfAttribute(attr);
|
|
892
|
-
predecessorCopiesOfParentAndChildAttributes.push(...predecessorCopies);
|
|
893
|
-
}
|
|
894
|
-
const attributeCopiesToDetach = [...copiesOfParentAndChildAttributes, ...predecessorCopiesOfParentAndChildAttributes];
|
|
895
|
-
await this.detachAttributeCopies(attributeCopiesToDetach);
|
|
896
|
-
await this.deletePredecessorsOfAttribute(attribute.id);
|
|
897
|
-
if (this.setDefaultRepositoryAttributes) {
|
|
898
|
-
await this.transferDefault(attribute);
|
|
640
|
+
const forwardedAttributes = (await this.getLocalAttributesExchangedWithPeer(peer, {
|
|
641
|
+
"@type": { $in: ["OwnIdentityAttribute", "OwnRelationshipAttribute", "PeerRelationshipAttribute"] }
|
|
642
|
+
}, undefined, true));
|
|
643
|
+
for (const attribute of forwardedAttributes) {
|
|
644
|
+
await this.removeForwardingDetailsFromAttribute(attribute, peer);
|
|
899
645
|
}
|
|
900
|
-
await this.deleteAttribute(attribute);
|
|
901
646
|
}
|
|
902
|
-
async
|
|
903
|
-
const
|
|
904
|
-
const
|
|
905
|
-
for (const
|
|
906
|
-
|
|
907
|
-
if (validateSuccessorResult.isError()) {
|
|
908
|
-
return validateSuccessorResult;
|
|
909
|
-
}
|
|
647
|
+
async removeForwardingDetailsFromAttribute(attribute, peer) {
|
|
648
|
+
const existingForwardingDetailsDocs = await this.forwardingDetails.find({ attributeId: attribute.id.toString(), peer: peer.toString() });
|
|
649
|
+
const existingForwardingDetails = existingForwardingDetailsDocs.map((obj) => AttributeForwardingDetails_1.AttributeForwardingDetails.from(obj));
|
|
650
|
+
for (const entry of existingForwardingDetails) {
|
|
651
|
+
await this.forwardingDetails.delete(entry);
|
|
910
652
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
const predecessorCopiesOfParentAndChildAttributes = [];
|
|
915
|
-
for (const attr of parentAndChildAttributes) {
|
|
916
|
-
const predecessorCopies = await this.getSharedPredecessorsOfAttribute(attr);
|
|
917
|
-
predecessorCopiesOfParentAndChildAttributes.push(...predecessorCopies);
|
|
918
|
-
}
|
|
919
|
-
const attributeCopiesToDetach = [...copiesOfParentAndChildAttributes, ...predecessorCopiesOfParentAndChildAttributes];
|
|
920
|
-
const validateSharedAttributesResult = this.validateSharedAttributes(attributeCopiesToDetach);
|
|
921
|
-
return validateSharedAttributesResult;
|
|
653
|
+
await this.updateNumberOfForwards(attribute);
|
|
654
|
+
this.eventBus.publish(new events_1.AttributeForwardingDetailsChangedEvent(this.identity.address.toString(), attribute));
|
|
655
|
+
return attribute;
|
|
922
656
|
}
|
|
923
|
-
async
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
657
|
+
async executeFullAttributeDeletionProcess(attribute) {
|
|
658
|
+
const validationResult = await this.validateFullAttributeDeletionProcess(attribute.id);
|
|
659
|
+
if (validationResult.isError())
|
|
660
|
+
throw validationResult.error;
|
|
661
|
+
if (attribute.succeededBy) {
|
|
662
|
+
const successor = await this.getLocalAttribute(attribute.succeededBy);
|
|
663
|
+
if (!successor)
|
|
664
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorDoesNotExist();
|
|
665
|
+
await this.detachSuccessor(successor);
|
|
929
666
|
}
|
|
930
|
-
|
|
667
|
+
await this.deletePredecessorsOfAttribute(attribute);
|
|
668
|
+
if (attribute instanceof OwnIdentityAttribute_1.OwnIdentityAttribute && this.setDefaultOwnIdentityAttributes)
|
|
669
|
+
await this.transferDefault(attribute);
|
|
670
|
+
await this.deleteAttribute(attribute.id);
|
|
931
671
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
672
|
+
async validateFullAttributeDeletionProcess(attributeId) {
|
|
673
|
+
const attribute = await this.getLocalAttribute(attributeId);
|
|
674
|
+
if (!attribute)
|
|
675
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attributeId.toString());
|
|
676
|
+
if (attribute.succeededBy) {
|
|
677
|
+
const successor = await this.getLocalAttribute(attribute.succeededBy);
|
|
678
|
+
if (!successor)
|
|
679
|
+
return common_1.ValidationResult.error(ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.successorDoesNotExist());
|
|
937
680
|
}
|
|
938
681
|
return common_1.ValidationResult.success();
|
|
939
682
|
}
|
|
@@ -941,89 +684,67 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
941
684
|
successor.succeeds = undefined;
|
|
942
685
|
await this.updateAttributeUnsafe(successor);
|
|
943
686
|
}
|
|
944
|
-
async
|
|
945
|
-
|
|
946
|
-
if (!sharedAttribute.isShared()) {
|
|
947
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.isNotSharedAttribute(sharedAttribute.id);
|
|
948
|
-
}
|
|
949
|
-
sharedAttribute.shareInfo.sourceAttribute = undefined;
|
|
950
|
-
await this.updateAttributeUnsafe(sharedAttribute);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
async deletePredecessorsOfAttribute(attributeId) {
|
|
954
|
-
const predecessors = await this.getPredecessorsOfAttribute(attributeId);
|
|
687
|
+
async deletePredecessorsOfAttribute(attribute) {
|
|
688
|
+
const predecessors = await this.getPredecessorsOfAttribute(attribute);
|
|
955
689
|
for (const predecessor of predecessors) {
|
|
956
|
-
await this.deleteAttribute(predecessor);
|
|
690
|
+
await this.deleteAttribute(predecessor.id);
|
|
957
691
|
}
|
|
958
692
|
}
|
|
959
693
|
async transferDefault(attribute) {
|
|
960
|
-
if (!this.
|
|
961
|
-
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.
|
|
694
|
+
if (!this.setDefaultOwnIdentityAttributes)
|
|
695
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.setDefaultOwnIdentityAttributesIsDisabled();
|
|
962
696
|
if (!attribute.isDefault)
|
|
963
697
|
return;
|
|
964
698
|
const valueType = attribute.content.value.constructor.name;
|
|
965
699
|
const query = {
|
|
966
700
|
$and: [
|
|
967
|
-
{
|
|
968
|
-
|
|
969
|
-
},
|
|
970
|
-
{
|
|
971
|
-
[(0, ts_simple_nameof_1.nameof)((c) => c.succeededBy)]: undefined
|
|
972
|
-
},
|
|
973
|
-
{
|
|
974
|
-
[(0, ts_simple_nameof_1.nameof)((c) => c.id)]: { $ne: attribute.id.toString() }
|
|
975
|
-
}
|
|
701
|
+
{ [`@type`]: "OwnIdentityAttribute" },
|
|
702
|
+
{ [`${(0, ts_simple_nameof_1.nameof)((c) => c.content)}.value.@type`]: valueType },
|
|
703
|
+
{ [(0, ts_simple_nameof_1.nameof)((c) => c.succeededBy)]: undefined },
|
|
704
|
+
{ [(0, ts_simple_nameof_1.nameof)((c) => c.id)]: { $ne: attribute.id.toString() } }
|
|
976
705
|
]
|
|
977
706
|
};
|
|
978
|
-
const defaultCandidates = await this.getLocalAttributes(query);
|
|
707
|
+
const defaultCandidates = (await this.getLocalAttributes(query));
|
|
979
708
|
if (defaultCandidates.length === 0)
|
|
980
709
|
return;
|
|
981
710
|
defaultCandidates[defaultCandidates.length - 1].isDefault = true;
|
|
982
711
|
await this.updateAttributeUnsafe(defaultCandidates[defaultCandidates.length - 1]);
|
|
983
712
|
}
|
|
984
|
-
async getVersionsOfAttribute(
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, id.toString());
|
|
988
|
-
}
|
|
989
|
-
const predecessors = await this.getPredecessorsOfAttribute(id);
|
|
990
|
-
const successors = await this.getSuccessorsOfAttribute(id);
|
|
713
|
+
async getVersionsOfAttribute(attribute) {
|
|
714
|
+
const predecessors = await this.getPredecessorsOfAttribute(attribute);
|
|
715
|
+
const successors = await this.getSuccessorsOfAttribute(attribute);
|
|
991
716
|
const allAttributeVersions = [...successors.reverse(), attribute, ...predecessors];
|
|
992
717
|
return allAttributeVersions;
|
|
993
718
|
}
|
|
994
|
-
async getPredecessorsOfAttribute(
|
|
995
|
-
let attribute = await this.getLocalAttribute(id);
|
|
996
|
-
if (!attribute) {
|
|
997
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, id.toString());
|
|
998
|
-
}
|
|
719
|
+
async getPredecessorsOfAttribute(attribute) {
|
|
999
720
|
const predecessors = [];
|
|
1000
721
|
while (attribute.succeeds) {
|
|
1001
|
-
const predecessor = await this.getLocalAttribute(attribute.succeeds);
|
|
1002
|
-
if (!predecessor)
|
|
722
|
+
const predecessor = (await this.getLocalAttribute(attribute.succeeds));
|
|
723
|
+
if (!predecessor)
|
|
1003
724
|
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attribute.succeeds.toString());
|
|
1004
|
-
}
|
|
1005
725
|
attribute = predecessor;
|
|
1006
726
|
predecessors.push(attribute);
|
|
1007
727
|
}
|
|
1008
728
|
return predecessors;
|
|
1009
729
|
}
|
|
1010
|
-
async getSuccessorsOfAttribute(
|
|
1011
|
-
let attribute = await this.getLocalAttribute(id);
|
|
1012
|
-
if (!attribute) {
|
|
1013
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, id.toString());
|
|
1014
|
-
}
|
|
730
|
+
async getSuccessorsOfAttribute(attribute) {
|
|
1015
731
|
const successors = [];
|
|
1016
732
|
while (attribute.succeededBy) {
|
|
1017
|
-
const successor = await this.getLocalAttribute(attribute.succeededBy);
|
|
1018
|
-
if (!successor)
|
|
733
|
+
const successor = (await this.getLocalAttribute(attribute.succeededBy));
|
|
734
|
+
if (!successor)
|
|
1019
735
|
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attribute.succeededBy.toString());
|
|
1020
|
-
}
|
|
1021
736
|
attribute = successor;
|
|
1022
737
|
successors.push(successor);
|
|
1023
738
|
}
|
|
1024
739
|
return successors;
|
|
1025
740
|
}
|
|
1026
|
-
async isSubsequentInSuccession(
|
|
741
|
+
async isSubsequentInSuccession(predecessorId, successorId) {
|
|
742
|
+
let predecessor = await this.getLocalAttribute(predecessorId);
|
|
743
|
+
if (!predecessor)
|
|
744
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, predecessorId.toString());
|
|
745
|
+
const successor = await this.getLocalAttribute(successorId);
|
|
746
|
+
if (!successor)
|
|
747
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, successorId.toString());
|
|
1027
748
|
while (predecessor.succeededBy) {
|
|
1028
749
|
const directSuccessor = await this.getLocalAttribute(predecessor.succeededBy);
|
|
1029
750
|
if (!directSuccessor)
|
|
@@ -1034,102 +755,131 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
1034
755
|
}
|
|
1035
756
|
return false;
|
|
1036
757
|
}
|
|
1037
|
-
async
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
if (
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
return ownSharedAttributeVersions;
|
|
1051
|
-
}
|
|
1052
|
-
async getSharedPredecessorsOfAttribute(sourceAttribute, query = {}) {
|
|
1053
|
-
const ownSharedAttributePredecessors = [];
|
|
1054
|
-
while (sourceAttribute.succeeds) {
|
|
1055
|
-
const predecessor = await this.getLocalAttribute(sourceAttribute.succeeds);
|
|
758
|
+
async getVersionsOfAttributeSharedWithPeer(attribute, peerAddress, onlyLatestVersion = true, excludeToBeDeleted = false) {
|
|
759
|
+
const sharedAttribute = (await this.isAttributeForwardedToPeer(attribute, peerAddress, excludeToBeDeleted)) ? [attribute] : [];
|
|
760
|
+
const sharedPredecessors = await this.getPredecessorsOfAttributeSharedWithPeer(attribute, peerAddress, excludeToBeDeleted);
|
|
761
|
+
const sharedSuccessors = await this.getSuccessorsOfAttributeSharedWithPeer(attribute, peerAddress, excludeToBeDeleted);
|
|
762
|
+
const sharedAttributeVersions = [...sharedSuccessors.reverse(), ...sharedAttribute, ...sharedPredecessors];
|
|
763
|
+
if (onlyLatestVersion)
|
|
764
|
+
return sharedAttributeVersions.length > 0 ? [sharedAttributeVersions[0]] : [];
|
|
765
|
+
return sharedAttributeVersions;
|
|
766
|
+
}
|
|
767
|
+
async getPredecessorsOfAttributeSharedWithPeer(referenceAttribute, peerAddress, excludeToBeDeleted = false) {
|
|
768
|
+
const matchingPredecessors = [];
|
|
769
|
+
while (referenceAttribute.succeeds) {
|
|
770
|
+
const predecessor = (await this.getLocalAttribute(referenceAttribute.succeeds));
|
|
1056
771
|
if (!predecessor)
|
|
1057
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute,
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
const successor = await this.getLocalAttribute(sourceAttribute.succeededBy);
|
|
772
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, referenceAttribute.succeeds.toString());
|
|
773
|
+
referenceAttribute = predecessor;
|
|
774
|
+
if (await this.isAttributeForwardedToPeer(referenceAttribute, peerAddress, excludeToBeDeleted))
|
|
775
|
+
matchingPredecessors.push(referenceAttribute);
|
|
776
|
+
}
|
|
777
|
+
return matchingPredecessors;
|
|
778
|
+
}
|
|
779
|
+
async getSuccessorsOfAttributeSharedWithPeer(referenceAttribute, peerAddress, excludeToBeDeleted = false) {
|
|
780
|
+
const matchingSuccessors = [];
|
|
781
|
+
while (referenceAttribute.succeededBy) {
|
|
782
|
+
const successor = (await this.getLocalAttribute(referenceAttribute.succeededBy));
|
|
1069
783
|
if (!successor)
|
|
1070
|
-
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute,
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
784
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, referenceAttribute.succeededBy.toString());
|
|
785
|
+
referenceAttribute = successor;
|
|
786
|
+
if (await this.isAttributeForwardedToPeer(referenceAttribute, peerAddress, excludeToBeDeleted))
|
|
787
|
+
matchingSuccessors.push(referenceAttribute);
|
|
788
|
+
}
|
|
789
|
+
return matchingSuccessors;
|
|
790
|
+
}
|
|
791
|
+
async getPeersWithExclusivelyForwardedPredecessors(attributeId) {
|
|
792
|
+
let attribute = (await this.getLocalAttribute(attributeId));
|
|
793
|
+
if (!attribute)
|
|
794
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attributeId.toString());
|
|
795
|
+
if (!(attribute instanceof OwnIdentityAttribute_1.OwnIdentityAttribute || attribute instanceof OwnRelationshipAttribute_1.OwnRelationshipAttribute || attribute instanceof PeerRelationshipAttribute_1.PeerRelationshipAttribute)) {
|
|
796
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongTypeOfAttribute(`The Attribute ${attributeId} is not an OwnIdentityAttribute, an OwnRelationshipAttribute or a PeerRelationshipAttribute.`);
|
|
797
|
+
}
|
|
798
|
+
const peersWithLaterSharedVersion = await this.getForwardingPeers(attribute, true);
|
|
799
|
+
const peersWithExclusivelyForwardedPredecessors = [];
|
|
800
|
+
while (attribute.succeeds) {
|
|
801
|
+
const predecessor = (await this.getLocalAttribute(attribute.succeeds));
|
|
802
|
+
if (!predecessor)
|
|
803
|
+
throw transport_1.TransportCoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attribute.succeeds.toString());
|
|
804
|
+
attribute = predecessor;
|
|
805
|
+
const forwardingPeers = await this.getForwardingPeers(attribute, true);
|
|
806
|
+
const newPeers = forwardingPeers.filter((peer) => !peersWithLaterSharedVersion.some((peerWithLaterSharedVersion) => peerWithLaterSharedVersion.equals(peer)));
|
|
807
|
+
if (newPeers.length === 0)
|
|
808
|
+
continue;
|
|
809
|
+
for (const peer of newPeers) {
|
|
810
|
+
peersWithExclusivelyForwardedPredecessors.push([peer, attribute.id]);
|
|
811
|
+
}
|
|
812
|
+
peersWithLaterSharedVersion.push(...newPeers);
|
|
1075
813
|
}
|
|
1076
|
-
return
|
|
814
|
+
return peersWithExclusivelyForwardedPredecessors;
|
|
815
|
+
}
|
|
816
|
+
async getOwnIdentityAttributeWithSameValue(value) {
|
|
817
|
+
const trimmedValue = this.trimAttributeValue(value);
|
|
818
|
+
const queryForOwnIdentityAttributeDuplicates = (0, common_1.flattenObject)({
|
|
819
|
+
"@type": "OwnIdentityAttribute",
|
|
820
|
+
content: { value: trimmedValue }
|
|
821
|
+
});
|
|
822
|
+
queryForOwnIdentityAttributeDuplicates["succeededBy"] = { $exists: false };
|
|
823
|
+
return (await this.getAttributeWithSameValue(trimmedValue, queryForOwnIdentityAttributeDuplicates));
|
|
1077
824
|
}
|
|
1078
|
-
async
|
|
825
|
+
async getPeerIdentityAttributeWithSameValue(value, owner) {
|
|
1079
826
|
const trimmedValue = this.trimAttributeValue(value);
|
|
1080
|
-
const
|
|
827
|
+
const query = (0, common_1.flattenObject)({
|
|
828
|
+
"@type": "PeerIdentityAttribute",
|
|
1081
829
|
content: {
|
|
1082
|
-
|
|
1083
|
-
owner:
|
|
1084
|
-
value: trimmedValue
|
|
830
|
+
value: trimmedValue,
|
|
831
|
+
owner: owner
|
|
1085
832
|
}
|
|
1086
833
|
});
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
return await this.getAttributeWithSameValue(trimmedValue, queryForRepositoryAttributeDuplicates);
|
|
834
|
+
query["deletionInfo.deletionStatus"] = { $ne: deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter };
|
|
835
|
+
return (await this.getAttributeWithSameValue(trimmedValue, query));
|
|
1090
836
|
}
|
|
1091
|
-
async
|
|
1092
|
-
const
|
|
1093
|
-
|
|
837
|
+
async getThirdPartyRelationshipAttributeWithSameValue(value, peer, owner, key) {
|
|
838
|
+
const query = (0, common_1.flattenObject)({
|
|
839
|
+
"@type": "ThirdPartyRelationshipAttribute",
|
|
1094
840
|
content: {
|
|
1095
|
-
|
|
1096
|
-
owner:
|
|
1097
|
-
|
|
1098
|
-
},
|
|
1099
|
-
shareInfo: {
|
|
1100
|
-
peer
|
|
841
|
+
value: value,
|
|
842
|
+
owner: owner,
|
|
843
|
+
key: key
|
|
1101
844
|
}
|
|
1102
845
|
});
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
return await this.getAttributeWithSameValue(
|
|
846
|
+
query["peer"] = peer;
|
|
847
|
+
query["deletionInfo.deletionStatus"] = { $ne: deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter };
|
|
848
|
+
return (await this.getAttributeWithSameValue(value, query));
|
|
1106
849
|
}
|
|
1107
850
|
async getAttributeWithSameValue(value, query) {
|
|
1108
851
|
const matchingAttributes = await this.getLocalAttributes(query);
|
|
1109
852
|
const attributeDuplicate = matchingAttributes.find((duplicate) => lodash_1.default.isEqual(duplicate.content.value.toJSON(), value));
|
|
1110
853
|
return attributeDuplicate;
|
|
1111
854
|
}
|
|
855
|
+
trimAttribute(attribute) {
|
|
856
|
+
const trimmedAttribute = {
|
|
857
|
+
...attribute.toJSON(),
|
|
858
|
+
value: this.trimAttributeValue(attribute.value.toJSON())
|
|
859
|
+
};
|
|
860
|
+
return content_1.IdentityAttribute.from(trimmedAttribute);
|
|
861
|
+
}
|
|
1112
862
|
trimAttributeValue(value) {
|
|
1113
863
|
const trimmedEntries = Object.entries(value).map((entry) => (typeof entry[1] === "string" ? [entry[0], entry[1].trim()] : entry));
|
|
1114
864
|
return Object.fromEntries(trimmedEntries);
|
|
1115
865
|
}
|
|
1116
866
|
async getRelationshipAttributesOfValueTypeToPeerWithGivenKeyAndOwner(key, owner, valueType, peer) {
|
|
1117
|
-
|
|
1118
|
-
"
|
|
867
|
+
const query = {
|
|
868
|
+
"@type": { $in: ["OwnRelationshipAttribute", "PeerRelationshipAttribute"] },
|
|
1119
869
|
"content.owner": owner.toString(),
|
|
1120
870
|
"content.key": key,
|
|
1121
871
|
"content.value.@type": valueType,
|
|
1122
|
-
|
|
1123
|
-
"shareInfo.thirdPartyAddress": { $exists: false },
|
|
872
|
+
peer: peer.toString(),
|
|
1124
873
|
"deletionInfo.deletionStatus": {
|
|
1125
874
|
$nin: [
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
875
|
+
deletionInfos_1.EmittedAttributeDeletionStatus.ToBeDeletedByRecipient,
|
|
876
|
+
deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient,
|
|
877
|
+
deletionInfos_1.ReceivedAttributeDeletionStatus.ToBeDeleted,
|
|
878
|
+
deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter
|
|
1130
879
|
]
|
|
1131
880
|
}
|
|
1132
|
-
}
|
|
881
|
+
};
|
|
882
|
+
return (await this.getLocalAttributes(query));
|
|
1133
883
|
}
|
|
1134
884
|
async getAttributeTagCollection() {
|
|
1135
885
|
if (this.readTagCollectionPromise) {
|
|
@@ -1273,37 +1023,102 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
1273
1023
|
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.wrongRelationshipStatusToSetDeletionInfo();
|
|
1274
1024
|
}
|
|
1275
1025
|
const deletionDate = relationship.auditLog[relationship.auditLog.length - 1].createdAt;
|
|
1276
|
-
await this.
|
|
1277
|
-
|
|
1026
|
+
await this.setDeletionInfoOfAttributesSharedWithPeer(relationship.peer.address, deletionDate);
|
|
1027
|
+
}
|
|
1028
|
+
async setDeletionInfoOfAttributesSharedWithPeer(peer, deletionDate) {
|
|
1029
|
+
await this.setForwardedDeletionInfoOfAttributes(peer, deletionDate);
|
|
1030
|
+
await this.setPeerDeletionInfoOfOwnRelationshipAttributes(peer, deletionDate);
|
|
1031
|
+
await this.setPeerDeletionInfoOfReceivedAttributes(peer, deletionDate);
|
|
1278
1032
|
}
|
|
1279
|
-
async
|
|
1280
|
-
const
|
|
1281
|
-
deletionStatus:
|
|
1033
|
+
async setForwardedDeletionInfoOfAttributes(peer, deletionDate) {
|
|
1034
|
+
const deletionInfo = deletionInfos_1.EmittedAttributeDeletionInfo.from({
|
|
1035
|
+
deletionStatus: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient,
|
|
1282
1036
|
deletionDate
|
|
1283
1037
|
});
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
"
|
|
1287
|
-
"deletionInfo.deletionStatus": { $ne: LocalAttributeDeletionInfo_1.LocalAttributeDeletionStatus.DeletedByPeer }
|
|
1038
|
+
const forwardingDetailsForPeer = await this.forwardingDetails.find({
|
|
1039
|
+
peer: peer.toString(),
|
|
1040
|
+
"deletionInfo.deletionStatus": { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient }
|
|
1288
1041
|
});
|
|
1289
|
-
|
|
1042
|
+
if (forwardingDetailsForPeer.length === 0)
|
|
1043
|
+
return;
|
|
1044
|
+
const attributesForwardedToPeer = (await this.getLocalAttributes({
|
|
1045
|
+
"@type": { $in: ["OwnIdentityAttribute", "OwnRelationshipAttribute", "PeerRelationshipAttribute"] },
|
|
1046
|
+
id: { $in: forwardingDetailsForPeer.map((detail) => detail.attributeId.toString()) }
|
|
1047
|
+
}));
|
|
1048
|
+
for (const attribute of attributesForwardedToPeer) {
|
|
1049
|
+
await this.setForwardedDeletionInfoOfAttribute(attribute, deletionInfo, peer);
|
|
1050
|
+
}
|
|
1290
1051
|
}
|
|
1291
|
-
async
|
|
1292
|
-
const
|
|
1293
|
-
deletionStatus:
|
|
1052
|
+
async setPeerDeletionInfoOfOwnRelationshipAttributes(peer, deletionDate) {
|
|
1053
|
+
const deletionInfo = deletionInfos_1.EmittedAttributeDeletionInfo.from({
|
|
1054
|
+
deletionStatus: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient,
|
|
1294
1055
|
deletionDate
|
|
1295
1056
|
});
|
|
1296
|
-
const
|
|
1297
|
-
"
|
|
1298
|
-
|
|
1299
|
-
"deletionInfo.deletionStatus": { $ne:
|
|
1057
|
+
const attributesSharedWithPeer = (await this.getLocalAttributes({
|
|
1058
|
+
"@type": "OwnRelationshipAttribute",
|
|
1059
|
+
peer: peer.toString(),
|
|
1060
|
+
"deletionInfo.deletionStatus": { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient }
|
|
1061
|
+
}));
|
|
1062
|
+
for (const attribute of attributesSharedWithPeer) {
|
|
1063
|
+
await this.setPeerDeletionInfoOfOwnRelationshipAttribute(attribute, deletionInfo);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
async setPeerDeletionInfoOfReceivedAttributes(peer, deletionDate) {
|
|
1067
|
+
const deletionInfo = deletionInfos_1.ReceivedAttributeDeletionInfo.from({
|
|
1068
|
+
deletionStatus: deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter,
|
|
1069
|
+
deletionDate
|
|
1300
1070
|
});
|
|
1301
|
-
await this.
|
|
1071
|
+
const attributesReceivedFromPeer = (await this.getLocalAttributes({
|
|
1072
|
+
"@type": { $in: ["PeerIdentityAttribute", "PeerRelationshipAttribute", "ThirdPartyRelationshipAttribute"] },
|
|
1073
|
+
peer: peer.toString(),
|
|
1074
|
+
"deletionInfo.deletionStatus": { $ne: deletionInfos_1.ReceivedAttributeDeletionStatus.DeletedByEmitter }
|
|
1075
|
+
}));
|
|
1076
|
+
for (const attribute of attributesReceivedFromPeer) {
|
|
1077
|
+
await this.setPeerDeletionInfoOfReceivedAttribute(attribute, deletionInfo);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
async setForwardedDeletionInfoOfAttribute(attribute, deletionInfo, peer, overrideDeletedOrToBeDeleted = false) {
|
|
1081
|
+
const isDeletedOrToBeDeletedByForwardingPeer = await this.isAttributeDeletedOrToBeDeletedByForwardingPeer(attribute, peer);
|
|
1082
|
+
if (isDeletedOrToBeDeletedByForwardingPeer && !overrideDeletedOrToBeDeleted)
|
|
1083
|
+
return;
|
|
1084
|
+
await this.setDeletionInfoForForwardingPeer(attribute, deletionInfo, peer, overrideDeletedOrToBeDeleted);
|
|
1085
|
+
}
|
|
1086
|
+
async isAttributeDeletedOrToBeDeletedByForwardingPeer(attribute, peer) {
|
|
1087
|
+
const docs = await this.forwardingDetails.find({ attributeId: attribute.id.toString(), peer: peer.toString() });
|
|
1088
|
+
const forwardingDetailsWithPeer = docs.map((doc) => AttributeForwardingDetails_1.AttributeForwardingDetails.from(doc));
|
|
1089
|
+
const deletionStatuses = [deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient, deletionInfos_1.EmittedAttributeDeletionStatus.ToBeDeletedByRecipient];
|
|
1090
|
+
const hasSharingDetailsWithDeletionStatus = forwardingDetailsWithPeer.some((details) => details.deletionInfo && deletionStatuses.includes(details.deletionInfo.deletionStatus));
|
|
1091
|
+
const hasSharingDetailsWithoutDeletionStatus = forwardingDetailsWithPeer.some((details) => !details.deletionInfo || !deletionStatuses.includes(details.deletionInfo.deletionStatus));
|
|
1092
|
+
return hasSharingDetailsWithDeletionStatus && !hasSharingDetailsWithoutDeletionStatus;
|
|
1093
|
+
}
|
|
1094
|
+
async setPeerDeletionInfoOfOwnRelationshipAttribute(attribute, deletionInfo, overrideDeletedOrToBeDeleted = false) {
|
|
1095
|
+
if (attribute.isDeletedOrToBeDeletedByRecipient() && !overrideDeletedOrToBeDeleted)
|
|
1096
|
+
return;
|
|
1097
|
+
attribute.setPeerDeletionInfo(deletionInfo, overrideDeletedOrToBeDeleted);
|
|
1098
|
+
await this.updateAttributeUnsafe(attribute);
|
|
1099
|
+
}
|
|
1100
|
+
async setPeerDeletionInfoOfReceivedAttribute(attribute, deletionInfo, overrideDeletedOrToBeDeleted = false) {
|
|
1101
|
+
if (attribute.isDeletedByEmitterOrToBeDeleted() && !overrideDeletedOrToBeDeleted)
|
|
1102
|
+
return;
|
|
1103
|
+
attribute.setPeerDeletionInfo(deletionInfo, overrideDeletedOrToBeDeleted);
|
|
1104
|
+
await this.updateAttributeUnsafe(attribute);
|
|
1105
|
+
}
|
|
1106
|
+
async setForwardedDeletionInfoOfAttributeAndPredecessors(attribute, deletionInfo, peer, overrideDeletedOrToBeDeleted = false) {
|
|
1107
|
+
const predecessors = await this.getPredecessorsOfAttribute(attribute);
|
|
1108
|
+
for (const attr of [attribute, ...predecessors]) {
|
|
1109
|
+
await this.setForwardedDeletionInfoOfAttribute(attr, deletionInfo, peer, overrideDeletedOrToBeDeleted);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
async setPeerDeletionInfoOfOwnRelationshipAttributeAndPredecessors(attribute, deletionInfo, overrideDeletedOrToBeDeleted = false) {
|
|
1113
|
+
const predecessors = await this.getPredecessorsOfAttribute(attribute);
|
|
1114
|
+
for (const attr of [attribute, ...predecessors]) {
|
|
1115
|
+
await this.setPeerDeletionInfoOfOwnRelationshipAttribute(attr, deletionInfo, overrideDeletedOrToBeDeleted);
|
|
1116
|
+
}
|
|
1302
1117
|
}
|
|
1303
|
-
async
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
await this.
|
|
1118
|
+
async setPeerDeletionInfoOfReceivedAttributeAndPredecessors(attribute, deletionInfo, overrideDeletedOrToBeDeleted = false) {
|
|
1119
|
+
const predecessors = await this.getPredecessorsOfAttribute(attribute);
|
|
1120
|
+
for (const attr of [attribute, ...predecessors]) {
|
|
1121
|
+
await this.setPeerDeletionInfoOfReceivedAttribute(attr, deletionInfo, overrideDeletedOrToBeDeleted);
|
|
1307
1122
|
}
|
|
1308
1123
|
}
|
|
1309
1124
|
async markAttributeAsViewed(id) {
|
|
@@ -1319,6 +1134,99 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
|
|
|
1319
1134
|
this.eventBus.publish(new events_1.AttributeWasViewedAtChangedEvent(this.identity.address.toString(), localAttribute));
|
|
1320
1135
|
return localAttribute;
|
|
1321
1136
|
}
|
|
1137
|
+
async isAttributeForwardedToPeer(attribute, peer, excludeToBeDeleted = false) {
|
|
1138
|
+
const forwardingDetails = await this.forwardingDetails.find({
|
|
1139
|
+
attributeId: attribute.id.toString(),
|
|
1140
|
+
peer: peer.toString(),
|
|
1141
|
+
"deletionInfo.deletionStatus": { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient }
|
|
1142
|
+
});
|
|
1143
|
+
if (forwardingDetails.length === 0)
|
|
1144
|
+
return false;
|
|
1145
|
+
if (!excludeToBeDeleted)
|
|
1146
|
+
return true;
|
|
1147
|
+
return forwardingDetails.some((details) => details.deletionInfo?.deletionStatus !== deletionInfos_1.EmittedAttributeDeletionStatus.ToBeDeletedByRecipient);
|
|
1148
|
+
}
|
|
1149
|
+
async getForwardingDetailsForPeer(attribute, peer, excludeDeletedByRecipient = false) {
|
|
1150
|
+
const query = { attributeId: attribute.id.toString(), peer: peer.toString() };
|
|
1151
|
+
if (excludeDeletedByRecipient)
|
|
1152
|
+
query["deletionInfo.deletionStatus"] = { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient };
|
|
1153
|
+
const existingForwardingDetails = await this.forwardingDetails.find(query);
|
|
1154
|
+
if (existingForwardingDetails.length === 0)
|
|
1155
|
+
return undefined;
|
|
1156
|
+
return AttributeForwardingDetails_1.AttributeForwardingDetails.from(existingForwardingDetails[0]);
|
|
1157
|
+
}
|
|
1158
|
+
async upsertForwardingDetailsForPeer(attribute, peer, forwardingDetails) {
|
|
1159
|
+
const existingForwardingDetails = await this.forwardingDetails.find({
|
|
1160
|
+
attributeId: attribute.id.toString(),
|
|
1161
|
+
peer: peer.toString(),
|
|
1162
|
+
"deletionInfo.deletionStatus": { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient }
|
|
1163
|
+
});
|
|
1164
|
+
if (existingForwardingDetails.length === 0) {
|
|
1165
|
+
await this.forwardingDetails.create(forwardingDetails);
|
|
1166
|
+
await this.updateNumberOfForwards(attribute);
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
await this.forwardingDetails.update(existingForwardingDetails[0], forwardingDetails);
|
|
1170
|
+
}
|
|
1171
|
+
async updateNumberOfForwards(attribute) {
|
|
1172
|
+
if (!(attribute instanceof OwnIdentityAttribute_1.OwnIdentityAttribute || attribute instanceof OwnRelationshipAttribute_1.OwnRelationshipAttribute || attribute instanceof PeerRelationshipAttribute_1.PeerRelationshipAttribute))
|
|
1173
|
+
return;
|
|
1174
|
+
const count = await this.forwardingDetails.count({ [(0, ts_simple_nameof_1.nameof)((c) => c.attributeId)]: attribute.id.toString() });
|
|
1175
|
+
attribute.numberOfForwards = count;
|
|
1176
|
+
}
|
|
1177
|
+
async getForwardingPeers(attribute, includeToBeDeleted = false) {
|
|
1178
|
+
const excludedDeletionStatuses = includeToBeDeleted
|
|
1179
|
+
? [deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient]
|
|
1180
|
+
: [deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient, deletionInfos_1.EmittedAttributeDeletionStatus.ToBeDeletedByRecipient];
|
|
1181
|
+
const forwardingDetailsDocs = await this.forwardingDetails.find({
|
|
1182
|
+
attributeId: attribute.id.toString(),
|
|
1183
|
+
"deletionInfo.deletionStatus": { $nin: excludedDeletionStatuses }
|
|
1184
|
+
});
|
|
1185
|
+
const forwardingDetails = forwardingDetailsDocs.map((doc) => AttributeForwardingDetails_1.AttributeForwardingDetails.from(doc));
|
|
1186
|
+
if (forwardingDetails.length === 0)
|
|
1187
|
+
return [];
|
|
1188
|
+
const peers = forwardingDetails.map((details) => details.peer.toString());
|
|
1189
|
+
const uniquePeers = [...new Set(peers)].map((address) => core_types_1.CoreAddress.from(address));
|
|
1190
|
+
return uniquePeers;
|
|
1191
|
+
}
|
|
1192
|
+
async setDeletionInfoForForwardingPeer(localAttribute, deletionInfo, peer, overrideDeleted = false) {
|
|
1193
|
+
const query = { attributeId: localAttribute.id.toString(), peer: peer.toString() };
|
|
1194
|
+
if (!overrideDeleted)
|
|
1195
|
+
query["deletionInfo.deletionStatus"] = { $ne: deletionInfos_1.EmittedAttributeDeletionStatus.DeletedByRecipient };
|
|
1196
|
+
const doc = await this.forwardingDetails.findOne(query);
|
|
1197
|
+
if (!doc)
|
|
1198
|
+
throw ConsumptionCoreErrors_1.ConsumptionCoreErrors.attributes.cannotSetAttributeDeletionInfo(localAttribute.id, peer);
|
|
1199
|
+
const forwardingDetails = AttributeForwardingDetails_1.AttributeForwardingDetails.from(doc);
|
|
1200
|
+
forwardingDetails.deletionInfo = deletionInfo;
|
|
1201
|
+
await this.forwardingDetails.update(doc, forwardingDetails);
|
|
1202
|
+
}
|
|
1203
|
+
async getForwardingDetailsForAttribute(attribute, query = {}) {
|
|
1204
|
+
const docs = await this.forwardingDetails.find({ ...query, attributeId: attribute.id.toString() });
|
|
1205
|
+
return docs.map((doc) => AttributeForwardingDetails_1.AttributeForwardingDetails.from(doc));
|
|
1206
|
+
}
|
|
1207
|
+
async getLocalAttributesExchangedWithPeer(peer, query, hideTechnical = false, onlyForwarded = false) {
|
|
1208
|
+
const forwardingDetailsDocs = await this.forwardingDetails.find({ peer: peer.toString() });
|
|
1209
|
+
const forwardingDetails = forwardingDetailsDocs.map((doc) => AttributeForwardingDetails_1.AttributeForwardingDetails.from(doc));
|
|
1210
|
+
const attributeIds = [...new Set(forwardingDetails.map((details) => details.attributeId.toString()))];
|
|
1211
|
+
if (onlyForwarded) {
|
|
1212
|
+
query.id = { $in: attributeIds.map((id) => id.toString()) };
|
|
1213
|
+
}
|
|
1214
|
+
else {
|
|
1215
|
+
query.$or = [
|
|
1216
|
+
{
|
|
1217
|
+
id: { $in: attributeIds.map((id) => id.toString()) }
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
peer: peer.toString()
|
|
1221
|
+
}
|
|
1222
|
+
];
|
|
1223
|
+
}
|
|
1224
|
+
const docs = await this.attributes.find(this.addHideTechnicalToQuery(query, hideTechnical));
|
|
1225
|
+
const attributes = docs.map((doc) => LocalAttribute_1.LocalAttribute.from(doc));
|
|
1226
|
+
for (const attribute of attributes)
|
|
1227
|
+
await this.updateNumberOfForwards(attribute);
|
|
1228
|
+
return attributes;
|
|
1229
|
+
}
|
|
1322
1230
|
}
|
|
1323
1231
|
exports.AttributesController = AttributesController;
|
|
1324
1232
|
//# sourceMappingURL=AttributesController.js.map
|