Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed blank node filter in internal additions changelog to support setting a Thing with blank node(s) #1545

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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