inrupt / solid-client-js

Library for accessing data and managing permissions on data stored in a Solid Pod

Home Page:https://docs.inrupt.com/developer-tools/javascript/client-libraries/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The async litDataset methods manipulate the input LitDataset

Vinnl opened this issue · comments

Search terms you've used

immutability, LitDataset, Resource, ACL

Describe the bug

The async methods in litDataset.ts (or, if #161 gets implemented first, also the Resource-specific async methods) use Object.assign() to add metadata returned from the call to the Pod to the input Resource. However, Object.assign() also changes its first argument.

Normally, you'd solve that by passing an empty object as the first argument, and shift the other arguments one position. However, because LitDatasets actually are a class, that's not sufficient here, IIRC because the prototype chain doesn't get copied over.

As an additional complexity, some of these methods (specifically, saveAclFor() and deleteAclFor()) only operate on the metadata, and should hence work on both LitDatasets and, after #219, regular files.

Presumably, the solution here is to check whether a Resource is a file, in which case the file should be cloned in whatever way is appropriate, if it's a LitDataset, in which case it should use clone() from rdfjs.ts, or just metadata, in which case we can just initialise an empty object. Then, cloneLitStructs (which should probably be renamed as well, since we no longer use the term Struct) should be modified to operate on the resulting clone to copy over the relevant properties from the input Resource.

To Reproduce
Call saveLitDatasetAt() with a changed LitDataset. Afterwards, check .changeLog on the input LitDataset. Instead of still listing the changes that were applied to it, it is now empty.

Expected behavior

It should still list the changes applied before saving it.