@nmshd/consumption 7.0.0-alpha.70 → 7.0.0-alpha.71

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