@nmshd/consumption 7.0.0-openid4vc.6 → 7.1.0-openid4vc.1

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