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

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