Skip to content

Commit 81cbe4f

Browse files
committed
fix: removed blank node filter from internal changelog to allow things with blank nodes
1 parent 8a57127 commit 81cbe4f

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/thing/thing.internal.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,21 @@ export function internal_addAdditionsToChangeLog<Dataset extends SolidDataset>(
117117
: /* istanbul ignore next: This function always gets called after addDeletionsToChangeLog, so the ChangeLog always already exists in tests: */
118118
{ additions: [], deletions: [] };
119119

120-
const [newAdditions, newDeletions] = additions
121-
.filter((addition) => !containsBlankNode(addition))
122-
.reduce(
123-
([additionsAcc, deletionsAcc], addition) => {
124-
const existingDeletion = deletionsAcc.find((deletion) =>
125-
deletion.equals(addition)
126-
);
127-
if (typeof existingDeletion !== "undefined") {
128-
return [
129-
additionsAcc,
130-
deletionsAcc.filter((deletion) => !deletion.equals(addition)),
131-
];
132-
}
133-
return [additionsAcc.concat(addition), deletionsAcc];
134-
},
135-
[changeLog.additions, changeLog.deletions]
136-
);
120+
const [newAdditions, newDeletions] = additions.reduce(
121+
([additionsAcc, deletionsAcc], addition) => {
122+
const existingDeletion = deletionsAcc.find((deletion) =>
123+
deletion.equals(addition)
124+
);
125+
if (typeof existingDeletion !== "undefined") {
126+
return [
127+
additionsAcc,
128+
deletionsAcc.filter((deletion) => !deletion.equals(addition)),
129+
];
130+
}
131+
return [additionsAcc.concat(addition), deletionsAcc];
132+
},
133+
[changeLog.additions, changeLog.deletions]
134+
);
137135

138136
return freeze({
139137
...solidDataset,

src/thing/thing.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ describe("getThingAll", () => {
407407
describe("setThing", () => {
408408
const mockThing1Iri = "https://some.vocab/subject1";
409409
const mockThing2Iri = "https://some.vocab/subject2";
410+
const mockThing3Iri = "https://some.vocab/subject3";
410411
const mockThing1: ThingPersisted = {
411412
type: "Subject",
412413
url: mockThing1Iri,
@@ -425,6 +426,22 @@ describe("setThing", () => {
425426
},
426427
},
427428
};
429+
const mockThing3: ThingPersisted = {
430+
type: "Subject",
431+
url: mockThing3Iri,
432+
predicates: {
433+
["https://arbitrary.vocab/predicate"]: {
434+
namedNodes: ["https://arbitrary.vocab/object"],
435+
blankNodes: [
436+
{
437+
["https://arbitrary.vocab/blanknode/predicate"]: {
438+
namedNodes: ["https://arbitrary.vocab/blanknode/object"],
439+
},
440+
},
441+
],
442+
},
443+
},
444+
};
428445
function getMockDataset(things = [mockThing1, mockThing2]): SolidDataset {
429446
const solidDataset: SolidDataset = {
430447
type: "Dataset",
@@ -576,6 +593,12 @@ describe("setThing", () => {
576593
getThing(updatedDataset, "https://some.pod/resource#subjectName")
577594
).toStrictEqual(originalThing);
578595
});
596+
597+
it("will create blank nodes including in a Thing", () => {
598+
const dataset = getMockDataset([]);
599+
const updatedDataset = setThing(dataset, mockThing3);
600+
expect(updatedDataset.internal_changeLog.additions).not.toHaveLength(1);
601+
});
579602
});
580603

581604
describe("removeThing", () => {

0 commit comments

Comments
 (0)