Skip to content

Commit

Permalink
fix: removed blank node filter from internal changelog to allow thing…
Browse files Browse the repository at this point in the history
…s with blank nodes
  • Loading branch information
Maximvdw committed Apr 12, 2022
1 parent a2e1f01 commit 580fd39
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/thing/thing.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,21 @@ export function internal_addAdditionsToChangeLog<Dataset extends SolidDataset>(
: /* istanbul ignore next: This function always gets called after addDeletionsToChangeLog, so the ChangeLog always already exists in tests: */
{ additions: [], deletions: [] };

const [newAdditions, newDeletions] = additions
.filter((addition) => !containsBlankNode(addition))
.reduce(
([additionsAcc, deletionsAcc], addition) => {
const existingDeletion = deletionsAcc.find((deletion) =>
deletion.equals(addition)
);
if (typeof existingDeletion !== "undefined") {
return [
additionsAcc,
deletionsAcc.filter((deletion) => !deletion.equals(addition)),
];
}
return [additionsAcc.concat(addition), deletionsAcc];
},
[changeLog.additions, changeLog.deletions]
);
const [newAdditions, newDeletions] = additions.reduce(
([additionsAcc, deletionsAcc], addition) => {
const existingDeletion = deletionsAcc.find((deletion) =>
deletion.equals(addition)
);
if (typeof existingDeletion !== "undefined") {
return [
additionsAcc,
deletionsAcc.filter((deletion) => !deletion.equals(addition)),
];
}
return [additionsAcc.concat(addition), deletionsAcc];
},
[changeLog.additions, changeLog.deletions]
);

return freeze({
...solidDataset,
Expand Down
23 changes: 23 additions & 0 deletions src/thing/thing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ describe("getThingAll", () => {
describe("setThing", () => {
const mockThing1Iri = "https://some.vocab/subject1";
const mockThing2Iri = "https://some.vocab/subject2";
const mockThing3Iri = "https://some.vocab/subject3";
const mockThing1: ThingPersisted = {
type: "Subject",
url: mockThing1Iri,
Expand All @@ -425,6 +426,22 @@ describe("setThing", () => {
},
},
};
const mockThing3: ThingPersisted = {
type: "Subject",
url: mockThing3Iri,
predicates: {
["https://arbitrary.vocab/predicate"]: {
namedNodes: ["https://arbitrary.vocab/object"],
blankNodes: [
{
["https://arbitrary.vocab/blanknode/predicate"]: {
namedNodes: ["https://arbitrary.vocab/blanknode/object"],
},
},
],
},
},
};
function getMockDataset(things = [mockThing1, mockThing2]): SolidDataset {
const solidDataset: SolidDataset = {
type: "Dataset",
Expand Down Expand Up @@ -576,6 +593,12 @@ describe("setThing", () => {
getThing(updatedDataset, "https://some.pod/resource#subjectName")
).toStrictEqual(originalThing);
});

it("will create blank nodes including in a Thing", () => {
const dataset = getMockDataset([]);
const updatedDataset = setThing(dataset, mockThing3);
expect(updatedDataset.internal_changeLog.additions).not.toHaveLength(1);
});
});

describe("removeThing", () => {
Expand Down

0 comments on commit 580fd39

Please sign in to comment.