Skip to content

Commit 154ce79

Browse files
Remove validFrom and validTo from AbstractAttribute (#420)
* feat: update content * feat: update consumption * feat: update runtime * chore: schemas * chore: remove time frame tests * fix: tests * chore: remove *Current methods * chore: update decider module --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 94ef695 commit 154ce79

29 files changed

+39
-913
lines changed

packages/consumption/src/modules/attributes/AttributesController.ts

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -66,47 +66,6 @@ export class AttributesController extends ConsumptionBaseController {
6666
return this;
6767
}
6868

69-
public checkValid(attribute: LocalAttribute): boolean {
70-
const now = CoreDate.utc();
71-
if (!attribute.content.validFrom && !attribute.content.validTo) {
72-
return true;
73-
} else if (attribute.content.validFrom && !attribute.content.validTo && attribute.content.validFrom.isSameOrBefore(now)) {
74-
return true;
75-
} else if (!attribute.content.validFrom && attribute.content.validTo?.isSameOrAfter(now)) {
76-
return true;
77-
} else if (attribute.content.validFrom && attribute.content.validTo && attribute.content.validFrom.isSameOrBefore(now) && attribute.content.validTo.isSameOrAfter(now)) {
78-
return true;
79-
}
80-
return false;
81-
}
82-
83-
public findCurrent(attributes: LocalAttribute[]): LocalAttribute | undefined {
84-
const sorted = attributes.sort((a, b) => {
85-
return a.createdAt.compare(b.createdAt);
86-
});
87-
let current: LocalAttribute | undefined;
88-
for (const attribute of sorted) {
89-
if (this.checkValid(attribute)) {
90-
current = attribute;
91-
}
92-
}
93-
return current;
94-
}
95-
96-
public filterCurrent(attributes: LocalAttribute[]): LocalAttribute[] {
97-
const sorted = attributes.sort((a, b) => {
98-
return a.createdAt.compare(b.createdAt);
99-
});
100-
101-
const items = [];
102-
for (const attribute of sorted) {
103-
if (this.checkValid(attribute)) {
104-
items.push(attribute);
105-
}
106-
}
107-
return items;
108-
}
109-
11069
public async getLocalAttribute(id: CoreId): Promise<LocalAttribute | undefined> {
11170
const result = await this.attributes.findOne({
11271
[nameof<LocalAttribute>((c) => c.id)]: id.toString()
@@ -122,7 +81,11 @@ export class AttributesController extends ConsumptionBaseController {
12281
const parsed = this.parseArray(attributes, LocalAttribute);
12382
if (!onlyValid) return parsed;
12483

125-
return this.filterCurrent(parsed);
84+
const sorted = parsed.sort((a, b) => {
85+
return a.createdAt.compare(b.createdAt);
86+
});
87+
88+
return sorted;
12689
}
12790

12891
private enrichQuery(query: any, hideTechnical: boolean) {
Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { QueryTranslator } from "@js-soft/docdb-querytranslator";
22
import {
3-
AbstractAttributeJSON,
43
IdentityAttribute,
54
IdentityAttributeJSON,
65
IdentityAttributeQuery,
@@ -11,7 +10,6 @@ import {
1110
RelationshipAttributeQuery,
1211
ThirdPartyRelationshipAttributeQuery
1312
} from "@nmshd/content";
14-
import { CoreDate } from "@nmshd/core-types";
1513
import { nameof } from "ts-simple-nameof";
1614
import { ConsumptionError } from "../../../consumption/ConsumptionError";
1715
import { LocalAttribute } from "./LocalAttribute";
@@ -26,8 +24,6 @@ export class IdentityAttributeQueryTranslator {
2624
whitelist: {
2725
[nameof<IIdentityAttributeQuery>((x) => x.tags)]: true,
2826
[nameof<IIdentityAttributeQuery>((x) => x.valueType)]: true,
29-
[nameof<IIdentityAttributeQuery>((x) => x.validFrom)]: true,
30-
[nameof<IIdentityAttributeQuery>((x) => x.validTo)]: true,
3127
attributeType: true
3228
},
3329
alias: {
@@ -52,26 +48,6 @@ export class IdentityAttributeQueryTranslator {
5248
$contains: t
5349
}
5450
}));
55-
},
56-
// validFrom
57-
[nameof<IIdentityAttributeQuery>((x) => x.validFrom)]: (query: any, input: any) => {
58-
if (!input) {
59-
return;
60-
}
61-
const validFromUtcString = CoreDate.from(input).toISOString();
62-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validFrom)}`] = {
63-
$gte: validFromUtcString
64-
};
65-
},
66-
// validTo
67-
[nameof<IIdentityAttributeQuery>((x) => x.validTo)]: (query: any, input: any) => {
68-
if (!input) {
69-
return;
70-
}
71-
const validToUtcString = CoreDate.from(input).toISOString();
72-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validTo)}`] = {
73-
$lte: validToUtcString
74-
};
7551
}
7652
}
7753
});
@@ -85,8 +61,6 @@ export class RelationshipAttributeQueryTranslator {
8561
private static readonly translator = new QueryTranslator({
8662
whitelist: {
8763
[nameof<IRelationshipAttributeQuery>((x) => x.key)]: true,
88-
[nameof<IRelationshipAttributeQuery>((x) => x.validFrom)]: true,
89-
[nameof<IRelationshipAttributeQuery>((x) => x.validTo)]: true,
9064
[nameof<IRelationshipAttributeQuery>((x) => x.owner)]: true,
9165
attributeType: true
9266
},
@@ -97,28 +71,6 @@ export class RelationshipAttributeQueryTranslator {
9771
attributeType: `${nameof<LocalAttribute>((x) => x.content)}.@type`,
9872
// owner
9973
[nameof<IRelationshipAttributeQuery>((x) => x.owner)]: `${nameof<LocalAttribute>((x) => x.content)}.${nameof<RelationshipAttribute>((x) => x.owner)}`
100-
},
101-
custom: {
102-
// validFrom
103-
[nameof<IRelationshipAttributeQuery>((x) => x.validFrom)]: (query: any, input: any) => {
104-
if (!input) {
105-
return;
106-
}
107-
const validFromUtcString = CoreDate.from(input).toISOString();
108-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validFrom)}`] = {
109-
$gte: validFromUtcString
110-
};
111-
},
112-
// validTo
113-
[nameof<IRelationshipAttributeQuery>((x) => x.validTo)]: (query: any, input: any) => {
114-
if (!input) {
115-
return;
116-
}
117-
const validToUtcString = CoreDate.from(input).toISOString();
118-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validTo)}`] = {
119-
$lte: validToUtcString
120-
};
121-
}
12274
}
12375
});
12476
}
@@ -131,8 +83,6 @@ export class ThirdPartyRelationshipAttributeQueryTranslator {
13183
private static readonly translator = new QueryTranslator({
13284
whitelist: {
13385
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.key)]: true,
134-
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.validFrom)]: true,
135-
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.validTo)]: true,
13686
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.owner)]: true,
13787
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.thirdParty)]: true,
13888
attributeType: true
@@ -146,28 +96,6 @@ export class ThirdPartyRelationshipAttributeQueryTranslator {
14696
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.owner)]: `${nameof<LocalAttribute>((x) => x.content)}.${nameof<RelationshipAttribute>((x) => x.owner)}`,
14797
// peer
14898
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.thirdParty)]: `${nameof<LocalAttribute>((x) => x.shareInfo)}.${nameof<LocalAttributeShareInfo>((x) => x.peer)}`
149-
},
150-
custom: {
151-
// validFrom
152-
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.validFrom)]: (query: any, input: any) => {
153-
if (!input) {
154-
return;
155-
}
156-
const validFromUtcString = CoreDate.from(input).toISOString();
157-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validFrom)}`] = {
158-
$gte: validFromUtcString
159-
};
160-
},
161-
// validTo
162-
[nameof<IThirdPartyRelationshipAttributeQuery>((x) => x.validTo)]: (query: any, input: any) => {
163-
if (!input) {
164-
return;
165-
}
166-
const validToUtcString = CoreDate.from(input).toISOString();
167-
query[`${nameof<LocalAttribute>((x) => x.content)}.${nameof<AbstractAttributeJSON>((x) => x.validTo)}`] = {
168-
$lte: validToUtcString
169-
};
170-
}
17199
}
172100
});
173101
}

packages/consumption/src/modules/requests/itemProcessors/utility/validateAttributeMatchesWithQuery.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,6 @@ export default function validateAttributeMatchesWithQuery(
3737
);
3838
}
3939

40-
if (query instanceof IdentityAttributeQuery || query instanceof RelationshipAttributeQuery || query instanceof ThirdPartyRelationshipAttributeQuery) {
41-
if (
42-
(typeof query.validFrom === "undefined" && typeof attribute.validFrom !== "undefined") ||
43-
(typeof query.validFrom !== "undefined" && typeof attribute.validFrom !== "undefined" && query.validFrom.isBefore(attribute.validFrom))
44-
) {
45-
return ValidationResult.error(ConsumptionCoreErrors.requests.attributeQueryMismatch("The provided Attribute is not valid in the queried time frame."));
46-
}
47-
48-
if (
49-
(typeof query.validTo === "undefined" && typeof attribute.validTo !== "undefined") ||
50-
(typeof query.validTo !== "undefined" && typeof attribute.validTo !== "undefined" && query.validTo.isAfter(attribute.validTo))
51-
) {
52-
return ValidationResult.error(ConsumptionCoreErrors.requests.attributeQueryMismatch("The provided Attribute is not valid in the queried time frame."));
53-
}
54-
}
55-
5640
return ValidationResult.success();
5741
}
5842

packages/consumption/test/modules/attributes/AttributesController.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ describe("AttributesController", function () {
138138
city: "aCity",
139139
country: "DE"
140140
},
141-
validTo: CoreDate.utc(),
142141
owner: consumptionController.accountController.identity.address
143142
});
144143

@@ -176,7 +175,6 @@ describe("AttributesController", function () {
176175
city: "aCity",
177176
country: "DE"
178177
},
179-
validTo: CoreDate.utc(),
180178
owner: consumptionController.accountController.identity.address
181179
});
182180

@@ -2086,7 +2084,6 @@ describe("AttributesController", function () {
20862084
country: version0ChildValues[4],
20872085
state: "Berlin"
20882086
},
2089-
validTo: CoreDate.utc(),
20902087
owner: consumptionController.accountController.identity.address
20912088
});
20922089

@@ -2285,7 +2282,6 @@ describe("AttributesController", function () {
22852282
city: version0ChildValues[3],
22862283
country: version0ChildValues[4]
22872284
},
2288-
validTo: CoreDate.utc(),
22892285
owner: CoreAddress.from("peer")
22902286
});
22912287

packages/consumption/test/modules/requests/itemProcessors/readAttribute/ReadAttributeRequestItemProcessor.test.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,57 +1017,6 @@ describe("ReadAttributeRequestItemProcessor", function () {
10171017

10181018
expect(result).successfulValidationResult();
10191019
});
1020-
1021-
test("can be called with properties validFrom and validTo used in the query", async function () {
1022-
const requestItem = ReadAttributeRequestItem.from({
1023-
mustBeAccepted: true,
1024-
query: RelationshipAttributeQuery.from({
1025-
owner: sender.toString(),
1026-
key: "aKey",
1027-
validFrom: "2024-02-14T08:47:35.077Z",
1028-
validTo: "2024-02-14T09:35:12.824Z",
1029-
attributeCreationHints: {
1030-
valueType: "ProprietaryString",
1031-
title: "aTitle",
1032-
confidentiality: RelationshipAttributeConfidentiality.Public
1033-
}
1034-
})
1035-
});
1036-
const requestId = await ConsumptionIds.request.generate();
1037-
const request = LocalRequest.from({
1038-
id: requestId,
1039-
createdAt: CoreDate.utc(),
1040-
isOwn: false,
1041-
peer: sender,
1042-
status: LocalRequestStatus.DecisionRequired,
1043-
content: Request.from({
1044-
id: requestId,
1045-
items: [requestItem]
1046-
}),
1047-
statusLog: []
1048-
});
1049-
1050-
const acceptParams: AcceptReadAttributeRequestItemParametersWithNewAttributeJSON = {
1051-
accept: true,
1052-
newAttribute: {
1053-
"@type": "RelationshipAttribute",
1054-
key: "aKey",
1055-
confidentiality: RelationshipAttributeConfidentiality.Public,
1056-
owner: sender.toString(),
1057-
validFrom: "2024-02-14T08:40:35.077Z",
1058-
validTo: "2024-02-14T09:35:12.824Z",
1059-
value: {
1060-
"@type": "ProprietaryString",
1061-
title: "aTitle",
1062-
value: "aStringValue"
1063-
}
1064-
}
1065-
};
1066-
1067-
const result = await processor.canAccept(requestItem, acceptParams, request);
1068-
1069-
expect(result).successfulValidationResult();
1070-
});
10711020
});
10721021

10731022
describe("canAccept ReadAttributeRequestitem with ThirdPartyRelationshipAttributeQuery", function () {

0 commit comments

Comments
 (0)