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

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