@nmshd/consumption 3.4.3 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/buildInformation.js +4 -4
  2. package/dist/consumption/CoreErrors.d.ts +14 -1
  3. package/dist/consumption/CoreErrors.js +56 -2
  4. package/dist/consumption/CoreErrors.js.map +1 -1
  5. package/dist/modules/attributes/AttributesController.d.ts +37 -6
  6. package/dist/modules/attributes/AttributesController.js +352 -45
  7. package/dist/modules/attributes/AttributesController.js.map +1 -1
  8. package/dist/modules/attributes/events/AttributeSucceededEventData.d.ts +5 -0
  9. package/dist/modules/attributes/events/AttributeSucceededEventData.js +3 -0
  10. package/dist/modules/attributes/events/AttributeSucceededEventData.js.map +1 -0
  11. package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.d.ts +7 -0
  12. package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.js +12 -0
  13. package/dist/modules/attributes/events/OwnSharedAttributeSucceededEvent.js.map +1 -0
  14. package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.d.ts +7 -0
  15. package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.js +12 -0
  16. package/dist/modules/attributes/events/PeerSharedAttributeSucceededEvent.js.map +1 -0
  17. package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.d.ts +7 -0
  18. package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.js +12 -0
  19. package/dist/modules/attributes/events/RepositoryAttributeSucceededEvent.js.map +1 -0
  20. package/dist/modules/attributes/events/index.d.ts +4 -1
  21. package/dist/modules/attributes/events/index.js +4 -1
  22. package/dist/modules/attributes/events/index.js.map +1 -1
  23. package/dist/modules/attributes/index.d.ts +1 -2
  24. package/dist/modules/attributes/index.js +1 -2
  25. package/dist/modules/attributes/index.js.map +1 -1
  26. package/dist/modules/attributes/local/CreateLocalAttributeParams.d.ts +12 -1
  27. package/dist/modules/attributes/local/CreateLocalAttributeParams.js +18 -2
  28. package/dist/modules/attributes/local/CreateLocalAttributeParams.js.map +1 -1
  29. package/dist/modules/attributes/local/IAttributeSuccessorParams.d.ts +6 -0
  30. package/dist/modules/attributes/local/IAttributeSuccessorParams.js +3 -0
  31. package/dist/modules/attributes/local/IAttributeSuccessorParams.js.map +1 -0
  32. package/dist/modules/attributes/local/LocalAttribute.d.ts +51 -11
  33. package/dist/modules/attributes/local/LocalAttribute.js +45 -11
  34. package/dist/modules/attributes/local/LocalAttribute.js.map +1 -1
  35. package/dist/modules/attributes/local/LocalAttributeShareInfo.d.ts +16 -7
  36. package/dist/modules/attributes/local/LocalAttributeShareInfo.js +21 -2
  37. package/dist/modules/attributes/local/LocalAttributeShareInfo.js.map +1 -1
  38. package/dist/modules/common/ValidationResult.js.map +1 -0
  39. package/dist/modules/common/index.d.ts +1 -0
  40. package/dist/modules/common/index.js +18 -0
  41. package/dist/modules/common/index.js.map +1 -0
  42. package/dist/modules/index.d.ts +1 -0
  43. package/dist/modules/index.js +1 -0
  44. package/dist/modules/index.js.map +1 -1
  45. package/dist/modules/notifications/NotificationsController.js +4 -5
  46. package/dist/modules/notifications/NotificationsController.js.map +1 -1
  47. package/dist/modules/notifications/itemProcessors/AbstractNotificationItemProcessor.d.ts +19 -12
  48. package/dist/modules/notifications/itemProcessors/AbstractNotificationItemProcessor.js.map +1 -1
  49. package/dist/modules/notifications/itemProcessors/attributeSucceeded/AttributeSucceededNotificationItemProcessor.d.ts +10 -4
  50. package/dist/modules/notifications/itemProcessors/attributeSucceeded/AttributeSucceededNotificationItemProcessor.js +67 -7
  51. package/dist/modules/notifications/itemProcessors/attributeSucceeded/AttributeSucceededNotificationItemProcessor.js.map +1 -1
  52. package/dist/modules/requests/incoming/DecideRequestParametersValidator.d.ts +1 -1
  53. package/dist/modules/requests/incoming/DecideRequestParametersValidator.js +1 -1
  54. package/dist/modules/requests/incoming/DecideRequestParametersValidator.js.map +1 -1
  55. package/dist/modules/requests/incoming/IncomingRequestsController.d.ts +1 -1
  56. package/dist/modules/requests/incoming/IncomingRequestsController.js +1 -1
  57. package/dist/modules/requests/incoming/IncomingRequestsController.js.map +1 -1
  58. package/dist/modules/requests/index.d.ts +0 -1
  59. package/dist/modules/requests/index.js +0 -1
  60. package/dist/modules/requests/index.js.map +1 -1
  61. package/dist/modules/requests/itemProcessors/AbstractRequestItemProcessor.d.ts +1 -1
  62. package/dist/modules/requests/itemProcessors/GenericRequestItemProcessor.d.ts +1 -1
  63. package/dist/modules/requests/itemProcessors/GenericRequestItemProcessor.js +1 -1
  64. package/dist/modules/requests/itemProcessors/GenericRequestItemProcessor.js.map +1 -1
  65. package/dist/modules/requests/itemProcessors/IRequestItemProcessor.d.ts +1 -1
  66. package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.d.ts +1 -1
  67. package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js +6 -3
  68. package/dist/modules/requests/itemProcessors/createAttribute/CreateAttributeRequestItemProcessor.js.map +1 -1
  69. package/dist/modules/requests/itemProcessors/freeText/FreeTextRequestItemProcessor.d.ts +1 -1
  70. package/dist/modules/requests/itemProcessors/freeText/FreeTextRequestItemProcessor.js +1 -1
  71. package/dist/modules/requests/itemProcessors/freeText/FreeTextRequestItemProcessor.js.map +1 -1
  72. package/dist/modules/requests/itemProcessors/proposeAttribute/AcceptProposeAttributeRequestItemParameters.js +2 -2
  73. package/dist/modules/requests/itemProcessors/proposeAttribute/AcceptProposeAttributeRequestItemParameters.js.map +1 -1
  74. package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.d.ts +1 -1
  75. package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js +1 -1
  76. package/dist/modules/requests/itemProcessors/proposeAttribute/ProposeAttributeRequestItemProcessor.js.map +1 -1
  77. package/dist/modules/requests/itemProcessors/readAttribute/AcceptReadAttributeRequestItemParameters.js +2 -2
  78. package/dist/modules/requests/itemProcessors/readAttribute/AcceptReadAttributeRequestItemParameters.js.map +1 -1
  79. package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.d.ts +1 -1
  80. package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js +1 -1
  81. package/dist/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.js.map +1 -1
  82. package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.d.ts +1 -1
  83. package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js +1 -1
  84. package/dist/modules/requests/itemProcessors/shareAttribute/ShareAttributeRequestItemProcessor.js.map +1 -1
  85. package/dist/modules/requests/itemProcessors/utility/validateQuery.d.ts +1 -1
  86. package/dist/modules/requests/itemProcessors/utility/validateQuery.js +1 -1
  87. package/dist/modules/requests/itemProcessors/utility/validateQuery.js.map +1 -1
  88. package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts +1 -1
  89. package/dist/modules/requests/outgoing/OutgoingRequestsController.js +1 -1
  90. package/dist/modules/requests/outgoing/OutgoingRequestsController.js.map +1 -1
  91. package/lib-web/nmshd.consumption.js +738 -230
  92. package/lib-web/nmshd.consumption.js.map +1 -1
  93. package/lib-web/nmshd.consumption.min.js +1 -1
  94. package/lib-web/nmshd.consumption.min.js.map +1 -1
  95. package/package.json +2 -2
  96. package/dist/modules/attributes/events/AttributeSucceededEvent.d.ts +0 -6
  97. package/dist/modules/attributes/events/AttributeSucceededEvent.js +0 -12
  98. package/dist/modules/attributes/events/AttributeSucceededEvent.js.map +0 -1
  99. package/dist/modules/attributes/local/SucceedLocalAttributeParams.d.ts +0 -16
  100. package/dist/modules/attributes/local/SucceedLocalAttributeParams.js +0 -32
  101. package/dist/modules/attributes/local/SucceedLocalAttributeParams.js.map +0 -1
  102. package/dist/modules/attributes/local/UpdateLocalAttributeParams.d.ts +0 -16
  103. package/dist/modules/attributes/local/UpdateLocalAttributeParams.js +0 -32
  104. package/dist/modules/attributes/local/UpdateLocalAttributeParams.js.map +0 -1
  105. package/dist/modules/requests/itemProcessors/ValidationResult.js.map +0 -1
  106. /package/dist/modules/{requests/itemProcessors → common}/ValidationResult.d.ts +0 -0
  107. /package/dist/modules/{requests/itemProcessors → common}/ValidationResult.js +0 -0
@@ -6,10 +6,10 @@ const content_1 = require("@nmshd/content");
6
6
  const crypto_1 = require("@nmshd/crypto");
7
7
  const transport_1 = require("@nmshd/transport");
8
8
  exports.buildInformation = {
9
- version: "3.4.3",
10
- build: "111",
11
- date: "2023-10-20T10:27:10+00:00",
12
- commit: "39c256999ae24a9eab143a39cfe470d69a3c4e40",
9
+ version: "3.5.1",
10
+ build: "113",
11
+ date: "2023-10-31T14:01:53+00:00",
12
+ commit: "b4bf86f640160bfe11c2e1fec16d54ddd43371a1",
13
13
  dependencies: {"@js-soft/docdb-querytranslator":"^1.1.1","@nmshd/iql":"^0.0.4","ts-simple-nameof":"^1.3.1"},
14
14
  libraries: {
15
15
  transport: transport_1.buildInformation,
@@ -1,7 +1,20 @@
1
1
  import { ApplicationError } from "@js-soft/ts-utils";
2
2
  import { CoreError, CoreId } from "@nmshd/transport";
3
3
  declare class Attributes {
4
- cannotSucceedAttributesWithAParent(parentId: string | CoreId): CoreError;
4
+ successionMustNotChangeKey(): CoreError;
5
+ successionPeerIsNotOwner(): CoreError;
6
+ invalidSuccessionOfOwnSharedIdentityAttribute(comment?: string): CoreError;
7
+ cannotSucceedPartOfComplexAttribute(parentId: string | CoreId): CoreError;
8
+ successorMustNotYetExist(): CoreError;
9
+ successorMustNotHaveASuccessor(comment?: string): CoreError;
10
+ invalidPredecessor(comment?: string): CoreError;
11
+ invalidSuccessor(comment?: string): CoreError;
12
+ predecessorDoesNotExist(): CoreError;
13
+ successionMustNotChangeOwner(): CoreError;
14
+ successionMustNotChangeValueType(): CoreError;
15
+ successionMustNotChangeContentType(): CoreError;
16
+ successionMustNotChangePeer(comment?: string): CoreError;
17
+ cannotSucceedAttributesWithASuccessor(successorId: string | CoreId): CoreError;
5
18
  }
6
19
  declare class Requests {
7
20
  unexpectedErrorDuringRequestItemProcessing(error: any): CoreError;
@@ -4,8 +4,62 @@ exports.CoreErrors = void 0;
4
4
  const ts_utils_1 = require("@js-soft/ts-utils");
5
5
  const transport_1 = require("@nmshd/transport");
6
6
  class Attributes {
7
- cannotSucceedAttributesWithAParent(parentId) {
8
- return new transport_1.CoreError("error.consumption.attributes.cannotSucceedAttributesWithAParent", `The Attribute you want to succeed has a parent (id: ${parentId.toString()}). You cannot succeed Attributes with a parent. Instead, succeed the parent, which will implicitly succeed all its children.`);
7
+ successionMustNotChangeKey() {
8
+ return new transport_1.CoreError("error.consumption.attributes.successionMustNotChangeKey", "The predecessor attribute's key does not match that of the successor. The succession of a relationship attribute must not change the key.");
9
+ }
10
+ successionPeerIsNotOwner() {
11
+ return new transport_1.CoreError("error.consumption.attributes.successionPeerIsNotOwner", "The peer of the succeeded attribute is not its owner. This may be an attempt of spoofing.");
12
+ }
13
+ invalidSuccessionOfOwnSharedIdentityAttribute(comment) {
14
+ let errorMessage = "Invalid succession of own shared identity attribute.";
15
+ if (comment)
16
+ errorMessage += ` ${comment}`;
17
+ return new transport_1.CoreError("error.consumption.attributes.invalidSuccessionOfOwnSharedIdentityAttribute", errorMessage);
18
+ }
19
+ cannotSucceedPartOfComplexAttribute(parentId) {
20
+ return new transport_1.CoreError("error.consumption.attributes.cannotSucceedPartOfComplexAttribute", `The attribute you want to succeed is part of a complex attribute (id: ${parentId}), and cannot be succeeded on its own. Instead, succeed the parent which will implicitly succeed all its children.`);
21
+ }
22
+ successorMustNotYetExist() {
23
+ return new transport_1.CoreError("error.consumption.attributes.successorMustNotYetExist", "The predecessor attribute's successor must not exist. It will be created by the succession handlers and must not be created manually.");
24
+ }
25
+ successorMustNotHaveASuccessor(comment) {
26
+ let errorMessage = "The successor must not have a successor itself.";
27
+ if (comment)
28
+ errorMessage += ` ${comment}`;
29
+ return new transport_1.CoreError("error.consumption.attributes.successorMustNotHaveASuccessor", errorMessage);
30
+ }
31
+ invalidPredecessor(comment) {
32
+ let errorMessage = "Invalid predecessor.";
33
+ if (comment)
34
+ errorMessage += ` ${comment}`;
35
+ return new transport_1.CoreError("error.consumption.attributes.invalidPredecessor", errorMessage);
36
+ }
37
+ invalidSuccessor(comment) {
38
+ let errorMessage = "Invalid successor.";
39
+ if (comment)
40
+ errorMessage += ` ${comment}`;
41
+ return new transport_1.CoreError("error.consumption.attributes.invalidSuccessor", errorMessage);
42
+ }
43
+ predecessorDoesNotExist() {
44
+ return new transport_1.CoreError("error.consumption.attributes.predecessorDoesNotExist", "The predecessor does not exist.");
45
+ }
46
+ successionMustNotChangeOwner() {
47
+ return new transport_1.CoreError("error.consumption.attributes.successionMustNotChangeOwner", "The successor attribute's owner does not match that of the predecessor. An attribute succession must not change the attribute's owner.");
48
+ }
49
+ successionMustNotChangeValueType() {
50
+ return new transport_1.CoreError("error.consumption.attributes.successionMustNotChangeValueType", "The successor attribute's value type does not match that of the predecessor. An attribute succession must not change the attribute's value type.");
51
+ }
52
+ successionMustNotChangeContentType() {
53
+ return new transport_1.CoreError("error.consumption.attributes.successionMustNotChangeContentType", "The successor attribute's content type does not match that of the predecessor. An attribute succession must not change the attribute's content type, i.e. an identity attribute must not be succeeded by a relationship attribute and v.v.");
54
+ }
55
+ successionMustNotChangePeer(comment) {
56
+ let errorMessage = "The peer of the shared attribute must not change.";
57
+ if (comment)
58
+ errorMessage += ` ${comment}`;
59
+ return new transport_1.CoreError("error.consumption.attributes.successionMustNotChangePeer", errorMessage);
60
+ }
61
+ cannotSucceedAttributesWithASuccessor(successorId) {
62
+ return new transport_1.CoreError("error.consumption.attributes.cannotSucceedAttributesWithASuccessor", `The Attribute you want to succeed has a successor (id: ${successorId}). You cannot succeed Attributes with a successor. Instead, succeed the successor.`);
9
63
  }
10
64
  }
11
65
  class Requests {
@@ -1 +1 @@
1
- {"version":3,"file":"CoreErrors.js","sourceRoot":"","sources":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B,oFAAoF,EACpF,qDAAqD,CACxD,CAAA;IACL,CAAC;IAEM,qCAAqC;QACxC,OAAO,IAAI,2BAAgB,CACvB,oFAAoF,EACpF,qDAAqD,CACxD,CAAA;IACL,CAAC;CACJ,AAhCwC,CAgCxC;AAKL,MAAa,UAAU;;AAAvB,gCAGC;AAFiB,qBAAU,GAAG,IAAI,UAAU,EAAE,CAAA;AAC7B,mBAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA"}
@@ -1,14 +1,14 @@
1
1
  import { EventBus } from "@js-soft/ts-utils";
2
2
  import { IIQLQuery, IIdentityAttributeQuery, IRelationshipAttributeQuery, IThirdPartyRelationshipAttributeQuery } from "@nmshd/content";
3
- import { CoreAddress, CoreId } from "@nmshd/transport";
3
+ import { CoreAddress, CoreId, ICoreDate, ICoreId } from "@nmshd/transport";
4
4
  import { ConsumptionBaseController } from "../../consumption/ConsumptionBaseController";
5
5
  import { ConsumptionController } from "../../consumption/ConsumptionController";
6
+ import { ValidationResult } from "../common";
6
7
  import { ICreateLocalAttributeParams } from "./local/CreateLocalAttributeParams";
7
8
  import { ICreatePeerLocalAttributeParams } from "./local/CreatePeerLocalAttributeParams";
8
9
  import { ICreateSharedLocalAttributeCopyParams } from "./local/CreateSharedLocalAttributeCopyParams";
9
- import { LocalAttribute } from "./local/LocalAttribute";
10
- import { ISucceedLocalAttributeParams } from "./local/SucceedLocalAttributeParams";
11
- import { IUpdateLocalAttributeParams } from "./local/UpdateLocalAttributeParams";
10
+ import { IAttributeSuccessorParams } from "./local/IAttributeSuccessorParams";
11
+ import { ILocalAttribute, LocalAttribute } from "./local/LocalAttribute";
12
12
  export declare class AttributesController extends ConsumptionBaseController {
13
13
  private readonly eventBus;
14
14
  private readonly identity;
@@ -30,9 +30,40 @@ export declare class AttributesController extends ConsumptionBaseController {
30
30
  executeIdentityAttributeQuery(query: IIdentityAttributeQuery): Promise<LocalAttribute[]>;
31
31
  createLocalAttribute(params: ICreateLocalAttributeParams): Promise<LocalAttribute>;
32
32
  private createLocalAttributesForNestedAttributeValues;
33
- succeedLocalAttribute(params: ISucceedLocalAttributeParams): Promise<LocalAttribute>;
34
33
  createSharedLocalAttributeCopy(params: ICreateSharedLocalAttributeCopyParams): Promise<LocalAttribute>;
35
34
  createPeerLocalAttribute(params: ICreatePeerLocalAttributeParams): Promise<LocalAttribute>;
36
- updateLocalAttribute(params: IUpdateLocalAttributeParams): Promise<LocalAttribute>;
37
35
  deleteAttribute(attribute: LocalAttribute): Promise<void>;
36
+ succeedRepositoryAttribute(predecessorId: CoreId, successorParams: IAttributeSuccessorParams, validate?: boolean): Promise<{
37
+ predecessor: LocalAttribute;
38
+ successor: LocalAttribute;
39
+ }>;
40
+ succeedOwnSharedIdentityAttribute(predecessorId: CoreId, successorParams: IAttributeSuccessorParams, validate?: boolean): Promise<{
41
+ predecessor: LocalAttribute;
42
+ successor: LocalAttribute;
43
+ }>;
44
+ succeedOwnSharedRelationshipAttribute(predecessorId: CoreId, successorParams: IAttributeSuccessorParams, validate?: boolean): Promise<{
45
+ predecessor: LocalAttribute;
46
+ successor: LocalAttribute;
47
+ }>;
48
+ succeedPeerSharedIdentityAttribute(predecessorId: CoreId, successorParams: IAttributeSuccessorParams, validate?: boolean): Promise<{
49
+ predecessor: LocalAttribute;
50
+ successor: LocalAttribute;
51
+ }>;
52
+ succeedPeerSharedRelationshipAttribute(predecessorId: CoreId, successorParams: IAttributeSuccessorParams, validate?: boolean): Promise<{
53
+ predecessor: LocalAttribute;
54
+ successor: LocalAttribute;
55
+ }>;
56
+ private _succeedAttributeUnsafe;
57
+ validateRepositoryAttributeSuccession(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
58
+ validateOwnSharedIdentityAttributeSuccession(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
59
+ validateOwnSharedRelationshipAttributeSuccession(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
60
+ validatePeerSharedIdentityAttributeSuccession(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
61
+ validatePeerSharedRelationshipAttributeSuccession(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
62
+ validateAttributeSuccessionCommon(predecessorId: CoreId, successorParams: IAttributeSuccessorParams): Promise<ValidationResult>;
63
+ createAttributeUnsafe(attributeData: Omit<ILocalAttribute, "id" | "createdAt"> & {
64
+ id?: ICoreId;
65
+ createdAt?: ICoreDate;
66
+ }): Promise<LocalAttribute>;
67
+ updateAttributeUnsafe(attributeParams: ILocalAttribute): Promise<LocalAttribute>;
68
+ deleteAttributeUnsafe(id: CoreId): Promise<void>;
38
69
  }
@@ -22,23 +22,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.AttributesController = void 0;
27
30
  const content_1 = require("@nmshd/content");
28
31
  const Iql = __importStar(require("@nmshd/iql"));
29
32
  const transport_1 = require("@nmshd/transport");
33
+ const lodash_1 = __importDefault(require("lodash"));
30
34
  const ts_simple_nameof_1 = require("ts-simple-nameof");
31
35
  const ConsumptionBaseController_1 = require("../../consumption/ConsumptionBaseController");
32
36
  const ConsumptionControllerName_1 = require("../../consumption/ConsumptionControllerName");
33
37
  const ConsumptionError_1 = require("../../consumption/ConsumptionError");
34
38
  const ConsumptionIds_1 = require("../../consumption/ConsumptionIds");
35
39
  const CoreErrors_1 = require("../../consumption/CoreErrors");
40
+ const common_1 = require("../common");
36
41
  const events_1 = require("./events");
42
+ const CreateLocalAttributeParams_1 = require("./local/CreateLocalAttributeParams");
37
43
  const CreateSharedLocalAttributeCopyParams_1 = require("./local/CreateSharedLocalAttributeCopyParams");
38
44
  const LocalAttribute_1 = require("./local/LocalAttribute");
39
45
  const LocalAttributeShareInfo_1 = require("./local/LocalAttributeShareInfo");
40
46
  const QueryTranslator_1 = require("./local/QueryTranslator");
41
- const SucceedLocalAttributeParams_1 = require("./local/SucceedLocalAttributeParams");
42
47
  class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseController {
43
48
  constructor(parent, eventBus, identity) {
44
49
  super(ConsumptionControllerName_1.ConsumptionControllerName.AttributesController, parent);
@@ -184,11 +189,14 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
184
189
  return this.parseArray(attributes, LocalAttribute_1.LocalAttribute);
185
190
  }
186
191
  async createLocalAttribute(params) {
192
+ const parsedParams = CreateLocalAttributeParams_1.CreateLocalAttributeParams.from(params);
187
193
  const localAttribute = LocalAttribute_1.LocalAttribute.from({
188
- id: await ConsumptionIds_1.ConsumptionIds.attribute.generate(),
194
+ id: parsedParams.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
189
195
  createdAt: transport_1.CoreDate.utc(),
190
- content: params.content,
191
- parentId: params.parentId
196
+ content: parsedParams.content,
197
+ parentId: parsedParams.parentId,
198
+ succeeds: parsedParams.succeeds,
199
+ shareInfo: parsedParams.shareInfo
192
200
  });
193
201
  await this.attributes.create(localAttribute);
194
202
  if (localAttribute.content instanceof content_1.IdentityAttribute && // nested Local Attributes should only be created for Identity Attributes
@@ -211,29 +219,6 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
211
219
  await this.createLocalAttribute({ content: nestedAttribute, parentId: localAttribute.id });
212
220
  }
213
221
  }
214
- async succeedLocalAttribute(params) {
215
- const parsedParams = SucceedLocalAttributeParams_1.SucceedLocalAttributeParams.from(params);
216
- const currentAttributeDoc = await this.attributes.findOne({
217
- [(0, ts_simple_nameof_1.nameof)((c) => c.id)]: params.succeeds.toString()
218
- });
219
- const currentAttribute = LocalAttribute_1.LocalAttribute.from(currentAttributeDoc);
220
- if (currentAttribute.parentId) {
221
- throw CoreErrors_1.CoreErrors.attributes.cannotSucceedAttributesWithAParent(parsedParams.succeeds.toString());
222
- }
223
- if (!currentAttributeDoc) {
224
- throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, parsedParams.succeeds.toString());
225
- }
226
- if (!parsedParams.successorContent.validFrom) {
227
- parsedParams.successorContent.validFrom = transport_1.CoreDate.utc();
228
- }
229
- const validFrom = parsedParams.successorContent.validFrom;
230
- currentAttribute.content.validTo = validFrom.subtract(1);
231
- await this.attributes.update(currentAttributeDoc, currentAttribute);
232
- const successor = await LocalAttribute_1.LocalAttribute.fromAttribute(parsedParams.successorContent, parsedParams.succeeds);
233
- await this.attributes.create(successor);
234
- this.eventBus.publish(new events_1.AttributeSucceededEvent(this.identity.address.toString(), successor));
235
- return successor;
236
- }
237
222
  async createSharedLocalAttributeCopy(params) {
238
223
  const parsedParams = CreateSharedLocalAttributeCopyParams_1.CreateSharedLocalAttributeCopyParams.from(params);
239
224
  const sourceAttribute = await this.getLocalAttribute(parsedParams.sourceAttributeId);
@@ -265,28 +250,350 @@ class AttributesController extends ConsumptionBaseController_1.ConsumptionBaseCo
265
250
  this.eventBus.publish(new events_1.AttributeCreatedEvent(this.identity.address.toString(), peerLocalAttribute));
266
251
  return peerLocalAttribute;
267
252
  }
268
- async updateLocalAttribute(params) {
269
- const current = await this.attributes.findOne({
270
- [(0, ts_simple_nameof_1.nameof)((c) => c.id)]: params.id.toString()
253
+ async deleteAttribute(attribute) {
254
+ await this.deleteAttributeUnsafe(attribute.id);
255
+ this.eventBus.publish(new events_1.AttributeDeletedEvent(this.identity.address.toString(), attribute));
256
+ }
257
+ async succeedRepositoryAttribute(predecessorId, successorParams, validate = true) {
258
+ if (validate) {
259
+ const validationResult = await this.validateRepositoryAttributeSuccession(predecessorId, successorParams);
260
+ if (validationResult.isError()) {
261
+ throw validationResult.error;
262
+ }
263
+ }
264
+ const { predecessor, successor } = await this._succeedAttributeUnsafe(predecessorId, {
265
+ id: successorParams.id,
266
+ content: successorParams.content,
267
+ succeeds: predecessorId,
268
+ shareInfo: successorParams.shareInfo,
269
+ parentId: successorParams.parentId,
270
+ createdAt: successorParams.createdAt,
271
+ succeededBy: successorParams.succeededBy
271
272
  });
272
- if (!current) {
273
- throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, params.id.toString());
273
+ this.eventBus.publish(new events_1.RepositoryAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
274
+ return { predecessor, successor };
275
+ }
276
+ async succeedOwnSharedIdentityAttribute(predecessorId, successorParams, validate = true) {
277
+ if (validate) {
278
+ const validationResult = await this.validateOwnSharedIdentityAttributeSuccession(predecessorId, successorParams);
279
+ if (validationResult.isError()) {
280
+ throw validationResult.error;
281
+ }
274
282
  }
275
- const updatedLocalAttribute = LocalAttribute_1.LocalAttribute.from({
276
- id: current.id,
277
- content: params.content,
278
- createdAt: current.createdAt,
279
- shareInfo: current.shareInfo,
280
- succeededBy: current.succeededBy,
281
- succeeds: current.succeeds
283
+ const { predecessor, successor } = await this._succeedAttributeUnsafe(predecessorId, {
284
+ id: successorParams.id,
285
+ content: successorParams.content,
286
+ succeeds: predecessorId,
287
+ shareInfo: successorParams.shareInfo,
288
+ parentId: successorParams.parentId,
289
+ createdAt: successorParams.createdAt,
290
+ succeededBy: successorParams.succeededBy
282
291
  });
283
- await this.attributes.update(current, updatedLocalAttribute);
284
- this.eventBus.publish(new events_1.AttributeUpdatedEvent(this.identity.address.toString(), updatedLocalAttribute));
285
- return updatedLocalAttribute;
292
+ this.eventBus.publish(new events_1.OwnSharedAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
293
+ return { predecessor, successor };
286
294
  }
287
- async deleteAttribute(attribute) {
288
- await this.attributes.delete(attribute);
289
- this.eventBus.publish(new events_1.AttributeDeletedEvent(this.identity.address.toString(), attribute));
295
+ async succeedOwnSharedRelationshipAttribute(predecessorId, successorParams, validate = true) {
296
+ if (validate) {
297
+ const validationResult = await this.validateOwnSharedRelationshipAttributeSuccession(predecessorId, successorParams);
298
+ if (validationResult.isError()) {
299
+ throw validationResult.error;
300
+ }
301
+ }
302
+ const { predecessor, successor } = await this._succeedAttributeUnsafe(predecessorId, {
303
+ id: successorParams.id,
304
+ content: successorParams.content,
305
+ succeeds: predecessorId,
306
+ shareInfo: successorParams.shareInfo,
307
+ parentId: successorParams.parentId,
308
+ createdAt: successorParams.createdAt,
309
+ succeededBy: successorParams.succeededBy
310
+ });
311
+ this.eventBus.publish(new events_1.OwnSharedAttributeSucceededEvent(this.identity.address.toString(), predecessor, successor));
312
+ return { predecessor, successor };
313
+ }
314
+ async succeedPeerSharedIdentityAttribute(predecessorId, successorParams, validate = true) {
315
+ if (validate) {
316
+ const validationResult = await this.validatePeerSharedIdentityAttributeSuccession(predecessorId, successorParams);
317
+ if (validationResult.isError()) {
318
+ throw validationResult.error;
319
+ }
320
+ }
321
+ const { predecessor, successor } = await this._succeedAttributeUnsafe(predecessorId, {
322
+ id: successorParams.id,
323
+ content: successorParams.content,
324
+ succeeds: predecessorId,
325
+ shareInfo: successorParams.shareInfo,
326
+ parentId: successorParams.parentId,
327
+ createdAt: successorParams.createdAt,
328
+ succeededBy: successorParams.succeededBy
329
+ });
330
+ /* No succeeded attribute event fired here. This is done by the notification system. */
331
+ return { predecessor, successor };
332
+ }
333
+ async succeedPeerSharedRelationshipAttribute(predecessorId, successorParams, validate = true) {
334
+ if (validate) {
335
+ const validationResult = await this.validatePeerSharedRelationshipAttributeSuccession(predecessorId, successorParams);
336
+ if (validationResult.isError()) {
337
+ throw validationResult.error;
338
+ }
339
+ }
340
+ const { predecessor, successor } = await this._succeedAttributeUnsafe(predecessorId, {
341
+ id: successorParams.id,
342
+ content: successorParams.content,
343
+ succeeds: predecessorId,
344
+ shareInfo: successorParams.shareInfo,
345
+ parentId: successorParams.parentId,
346
+ createdAt: successorParams.createdAt,
347
+ succeededBy: successorParams.succeededBy
348
+ });
349
+ /* No succeeded attribute event fired here. This is done by the notification system. */
350
+ return { predecessor, successor };
351
+ }
352
+ async _succeedAttributeUnsafe(predecessorId, successorParams) {
353
+ const successor = await this.createAttributeUnsafe({
354
+ id: successorParams.id,
355
+ content: successorParams.content,
356
+ succeeds: predecessorId,
357
+ shareInfo: successorParams.shareInfo,
358
+ parentId: successorParams.parentId,
359
+ createdAt: successorParams.createdAt,
360
+ succeededBy: successorParams.succeededBy
361
+ });
362
+ const predecessor = (await this.getLocalAttribute(predecessorId));
363
+ predecessor.succeededBy = successor.id;
364
+ await this.updateAttributeUnsafe(predecessor);
365
+ return { predecessor, successor };
366
+ }
367
+ async validateRepositoryAttributeSuccession(predecessorId, successorParams) {
368
+ const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, successorParams);
369
+ if (commonValidation.isError())
370
+ return commonValidation;
371
+ const predecessor = (await this.getLocalAttribute(predecessorId));
372
+ const successor = LocalAttribute_1.LocalAttribute.from({
373
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
374
+ content: successorParams.content,
375
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
376
+ succeeds: successorParams.succeeds,
377
+ succeededBy: successorParams.succeededBy,
378
+ shareInfo: successorParams.shareInfo,
379
+ parentId: successorParams.parentId
380
+ });
381
+ if (!predecessor.isIdentityAttribute() || predecessor.isShared()) {
382
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Predecessor is not a valid repository attribute."));
383
+ }
384
+ if (!successor.isIdentityAttribute() || successor.isShared()) {
385
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Successor is not a valid repository attribute."));
386
+ }
387
+ return common_1.ValidationResult.success();
388
+ }
389
+ async validateOwnSharedIdentityAttributeSuccession(predecessorId, successorParams) {
390
+ const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, successorParams);
391
+ if (commonValidation.isError())
392
+ return commonValidation;
393
+ const predecessor = (await this.getLocalAttribute(predecessorId));
394
+ const successor = LocalAttribute_1.LocalAttribute.from({
395
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
396
+ content: successorParams.content,
397
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
398
+ succeeds: successorParams.succeeds,
399
+ succeededBy: successorParams.succeededBy,
400
+ shareInfo: successorParams.shareInfo,
401
+ parentId: successorParams.parentId
402
+ });
403
+ if (!predecessor.isOwnSharedIdentityAttribute(this.identity.address)) {
404
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Predecessor is not a valid own shared identity attribute."));
405
+ }
406
+ if (!successor.isOwnSharedIdentityAttribute(this.identity.address)) {
407
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessor("Successor is not a valid peer shared identity attribute."));
408
+ }
409
+ if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
410
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangePeer());
411
+ }
412
+ /* Succession of own shared identity attribute must be matched by their
413
+ * respective repository attributes. */
414
+ const predecessorSource = await this.getLocalAttribute(predecessor.shareInfo.sourceAttribute);
415
+ const successorSource = await this.getLocalAttribute(successor.shareInfo.sourceAttribute);
416
+ if (typeof predecessorSource === "undefined" || !predecessorSource.isRepositoryAttribute()) {
417
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessionOfOwnSharedIdentityAttribute());
418
+ }
419
+ if (typeof successorSource === "undefined" || !successorSource.isRepositoryAttribute()) {
420
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessionOfOwnSharedIdentityAttribute("Source attribute is not a valid repository attribute."));
421
+ }
422
+ if (typeof successorSource.succeeds === "undefined" ||
423
+ !successorSource.succeeds.equals(predecessorSource.id) ||
424
+ typeof predecessorSource.succeededBy === "undefined" ||
425
+ !predecessorSource.succeededBy.equals(successorSource.id)) {
426
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessionOfOwnSharedIdentityAttribute("Prdeecessor source attribute is not succeeded by successor source attribute."));
427
+ }
428
+ const repositoryAttributeContentMatchesItsSharedAttribute = lodash_1.default.isEqual(predecessorSource.content, predecessor.content) &&
429
+ lodash_1.default.isEqual(successorSource.content, successor.content);
430
+ if (!repositoryAttributeContentMatchesItsSharedAttribute) {
431
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessionOfOwnSharedIdentityAttribute("Successor source attribute contents don't match successor shared attribute copy."));
432
+ }
433
+ return common_1.ValidationResult.success();
434
+ }
435
+ async validateOwnSharedRelationshipAttributeSuccession(predecessorId, successorParams) {
436
+ const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, successorParams);
437
+ if (commonValidation.isError())
438
+ return commonValidation;
439
+ const predecessor = (await this.getLocalAttribute(predecessorId));
440
+ const successor = LocalAttribute_1.LocalAttribute.from({
441
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
442
+ content: successorParams.content,
443
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
444
+ succeeds: successorParams.succeeds,
445
+ succeededBy: successorParams.succeededBy,
446
+ shareInfo: successorParams.shareInfo,
447
+ parentId: successorParams.parentId
448
+ });
449
+ if (!predecessor.isOwnSharedRelationshipAttribute(this.identity.address)) {
450
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Predecessor is not a valid own shared relationship attribute."));
451
+ }
452
+ if (!successor.isOwnSharedRelationshipAttribute(this.identity.address)) {
453
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessor("Successor is not a valid own shared relationship attribute."));
454
+ }
455
+ if (successor.content.key !== predecessor.content.key) {
456
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangeKey());
457
+ }
458
+ if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
459
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangePeer());
460
+ }
461
+ return common_1.ValidationResult.success();
462
+ }
463
+ async validatePeerSharedIdentityAttributeSuccession(predecessorId, successorParams) {
464
+ const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, successorParams);
465
+ if (commonValidation.isError())
466
+ return commonValidation;
467
+ const predecessor = (await this.getLocalAttribute(predecessorId));
468
+ const successor = LocalAttribute_1.LocalAttribute.from({
469
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
470
+ content: successorParams.content,
471
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
472
+ succeeds: successorParams.succeeds,
473
+ succeededBy: successorParams.succeededBy,
474
+ shareInfo: successorParams.shareInfo,
475
+ parentId: successorParams.parentId
476
+ });
477
+ if (!predecessor.isPeerSharedIdentityAttribute()) {
478
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Predecessor is not a valid peer shared identity attribute."));
479
+ }
480
+ if (!successor.isPeerSharedIdentityAttribute()) {
481
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessor("Successor is not a valid peer shared identity attribute."));
482
+ }
483
+ if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
484
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangePeer());
485
+ }
486
+ return common_1.ValidationResult.success();
487
+ }
488
+ async validatePeerSharedRelationshipAttributeSuccession(predecessorId, successorParams) {
489
+ const commonValidation = await this.validateAttributeSuccessionCommon(predecessorId, successorParams);
490
+ if (commonValidation.isError())
491
+ return commonValidation;
492
+ const predecessor = (await this.getLocalAttribute(predecessorId));
493
+ const successor = LocalAttribute_1.LocalAttribute.from({
494
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
495
+ content: successorParams.content,
496
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
497
+ succeeds: successorParams.succeeds,
498
+ succeededBy: successorParams.succeededBy,
499
+ shareInfo: successorParams.shareInfo,
500
+ parentId: successorParams.parentId
501
+ });
502
+ if (!predecessor.isPeerSharedRelationshipAttribute()) {
503
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("Predecessor is not a valid peer shared relationship attribute."));
504
+ }
505
+ if (!successor.isPeerSharedRelationshipAttribute()) {
506
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidSuccessor("Successor is not a valid peer shared relationship attribute."));
507
+ }
508
+ if (successor.content.key !== predecessor.content.key) {
509
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangeKey());
510
+ }
511
+ if (!predecessor.shareInfo.peer.equals(successor.shareInfo.peer)) {
512
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangePeer());
513
+ }
514
+ return common_1.ValidationResult.success();
515
+ }
516
+ async validateAttributeSuccessionCommon(predecessorId, successorParams) {
517
+ const successor = LocalAttribute_1.LocalAttribute.from({
518
+ id: transport_1.CoreId.from(successorParams.id ?? "dummy"),
519
+ content: successorParams.content,
520
+ createdAt: successorParams.createdAt ?? transport_1.CoreDate.utc(),
521
+ succeeds: successorParams.succeeds,
522
+ succeededBy: successorParams.succeededBy,
523
+ shareInfo: successorParams.shareInfo,
524
+ parentId: successorParams.parentId
525
+ });
526
+ if (typeof successorParams.id !== "undefined") {
527
+ const successor = await this.getLocalAttribute(transport_1.CoreId.from(successorParams.id));
528
+ if (typeof successor !== "undefined") {
529
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successorMustNotYetExist());
530
+ }
531
+ }
532
+ if (typeof successor.succeeds !== "undefined" && !predecessorId.equals(successor.succeeds.toString())) {
533
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.invalidPredecessor("The predecessor's id and the explicitly set value for the successor's succeeds field don't match."));
534
+ }
535
+ if (typeof successor.succeededBy !== "undefined") {
536
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successorMustNotHaveASuccessor());
537
+ }
538
+ if (typeof successor.parentId !== "undefined") {
539
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.cannotSucceedPartOfComplexAttribute(predecessorId.toString()));
540
+ }
541
+ const predecessor = await this.getLocalAttribute(predecessorId);
542
+ if (typeof predecessor === "undefined") {
543
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.predecessorDoesNotExist());
544
+ }
545
+ if (typeof predecessor.succeededBy !== "undefined") {
546
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.cannotSucceedAttributesWithASuccessor(predecessor.succeededBy.toString()));
547
+ }
548
+ if (predecessor.parentId) {
549
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.cannotSucceedPartOfComplexAttribute(predecessorId.toString()));
550
+ }
551
+ if (!predecessor.content.owner.equals(transport_1.CoreAddress.from(successor.content.owner))) {
552
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangeOwner());
553
+ }
554
+ if (successor.content.constructor !== predecessor.content.constructor) {
555
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangeContentType());
556
+ }
557
+ if (predecessor.content.value.constructor !== successor.content.value.constructor) {
558
+ return common_1.ValidationResult.error(CoreErrors_1.CoreErrors.attributes.successionMustNotChangeValueType());
559
+ }
560
+ return common_1.ValidationResult.success();
561
+ }
562
+ async createAttributeUnsafe(attributeData) {
563
+ const localAttribute = LocalAttribute_1.LocalAttribute.from({
564
+ id: attributeData.id ?? (await ConsumptionIds_1.ConsumptionIds.attribute.generate()),
565
+ content: attributeData.content,
566
+ createdAt: attributeData.createdAt ?? transport_1.CoreDate.utc(),
567
+ shareInfo: attributeData.shareInfo,
568
+ parentId: attributeData.parentId,
569
+ succeededBy: attributeData.succeededBy,
570
+ succeeds: attributeData.succeeds
571
+ });
572
+ await this.attributes.create(localAttribute);
573
+ return localAttribute;
574
+ }
575
+ async updateAttributeUnsafe(attributeParams) {
576
+ const doc = await this.attributes.findOne({
577
+ [(0, ts_simple_nameof_1.nameof)((c) => c.id)]: attributeParams.id.toString()
578
+ });
579
+ if (!doc) {
580
+ throw transport_1.CoreErrors.general.recordNotFound(LocalAttribute_1.LocalAttribute, attributeParams.id.toString());
581
+ }
582
+ const params = {
583
+ id: attributeParams.id,
584
+ content: attributeParams.content,
585
+ createdAt: attributeParams.createdAt,
586
+ parentId: attributeParams.parentId,
587
+ shareInfo: attributeParams.shareInfo,
588
+ succeededBy: attributeParams.succeededBy,
589
+ succeeds: attributeParams.succeeds
590
+ };
591
+ const newAttribute = LocalAttribute_1.LocalAttribute.from(params);
592
+ await this.attributes.update(doc, newAttribute);
593
+ return newAttribute;
594
+ }
595
+ async deleteAttributeUnsafe(id) {
596
+ await this.attributes.delete({ id: id });
290
597
  }
291
598
  }
292
599
  exports.AttributesController = AttributesController;