Skip to content

Commit

Permalink
Improve operations pre-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Feb 7, 2025
1 parent 59f35d6 commit 269bac7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/solid/RDFResourceProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ abstract class RDFResourceProperty {
}
}

public valueEquals(other: RDFResourceProperty): boolean {
const value = this.value instanceof Date ? this.value.getTime() : this.value;
const otherValue = other.value instanceof Date ? other.value.getTime() : other.value;

return value === otherValue;
}

protected getTurtleReference(
value: string | null,
documentUrl: string | null,
Expand Down
9 changes: 8 additions & 1 deletion src/solid/SolidClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,21 @@ describe('SolidClient', () => {
it('ignores idempotent operations', async () => {
// Arrange
const documentUrl = faker.internet.url();
const data = '<> <http://www.w3.org/2000/01/rdf-schema#label> "Things" .';
const now = new Date();
const data = `
<>
<http://www.w3.org/2000/01/rdf-schema#label> "Things" ;
<http://purl.org/dc/terms/modified>
"${now.toISOString()}"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
`;

StubFetcher.addFetchResponse(data);
StubFetcher.addFetchResponse();

// Act
await client.updateDocument(documentUrl, [
new UpdatePropertyOperation(RDFResourceProperty.literal(documentUrl, IRI('rdfs:label'), 'Things')),
new UpdatePropertyOperation(RDFResourceProperty.literal(documentUrl, IRI('purl:modified'), now)),
new UpdatePropertyOperation(RDFResourceProperty.literal(documentUrl, IRI('foaf:name'), 'Things')),
]);

Expand Down
8 changes: 6 additions & 2 deletions src/solid/SolidClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export default class SolidClient {
this.processChangeUrlOperations(document, operations);
this.processUpdatePropertyOperations(document, operations);

if (operations.length === 0) {
return;
}

document.resource(url)?.isType(LDP_CONTAINER)
? await this.updateContainerDocument(document, operations)
: await this.updateNonContainerDocument(document, operations, options);
Expand Down Expand Up @@ -566,8 +570,8 @@ export default class SolidClient {
if (
currentProperty &&
otherProperties.length === 0 &&
property.value === currentProperty.value &&
property.type === currentProperty.type
property.type === currentProperty.type &&
property.valueEquals(currentProperty)
) {
idempotentOperations.push(operation);
}
Expand Down

0 comments on commit 269bac7

Please sign in to comment.