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

Feat: Store content type parameters #1196

Merged
merged 15 commits into from
Mar 14, 2022
Merged

Conversation

Falx
Copy link
Contributor

@Falx Falx commented Mar 4, 2022

📁 Related issues

#458

✍️ Description

Initial plan, but will not implement now
Replacing the RepresentationMetadata#contentType currently in use (as a string) with an object that also contains the parsed parameters would lead to a lot of changes in the codebase (and in testing). The main issue being that the RepresentationMetadata class would no longer consist of only single <identifier> <predicate> <object> triples to store metadata. The new contentType would need something along the lines of this structure:

<> ma:format _:format.
_:format     solid-type:value     "application/json";
             solid-type:parameter _:parameter1.
_:parameter1 rdfs:label           "charset";
             solid-type:value     "utf-8".

All internal code that now works on the assumption that they can just set a metadata property with one predicate and one value breaks now. The same thing is true for code that removes this triple/quad by identifying it as the triple using the <ma:format> predicate.

Proposed solution
After some internal discussion with @joachimvh, we've decided on the following strategy for now:

  • Leave the current contentType syntactic sugar on the RepresentationMetadata class for now so that we don't break any existing code in the CSS.
  • Add a syntactic sugar for contentTypeObject to retrieve a new ContentType object with the following structure:
    {
       "value": "text/plain",
       "parameters" : {
           "chartset": "utf-8"
       }
    }
  • On setting the contentType, the optional parameter string is also parsed and stored in the RepresentationMetadata like this:
    <>       solid-meta:ContentTypeParameter _:param1.
    _:param1 rdfs:label                      "charset";
             solid-type:value                "utf-8".

This allows developers who want, to also request the complete ContentType object using metadata.contentTypeObject and use the parsed parameters. When assigning a new value to metadata.contentType, the parameters will first be cleared from the metadata. To explicitly remove all parameters and contentType: metadat.contentType = undefined does this for you.

I've added extra tests to test the behaviour described above.

✅ PR check list

Before this pull request can be merged, a core maintainer will check whether

  • this PR is labeled with the correct semver label
    • semver.patch: Backwards compatible bug fixes.
    • semver.minor: Backwards compatible feature additions.
    • semver.major: Breaking changes. This includes changing interfaces or configuration behaviour.
  • the correct branch is targeted. Patch updates can target main, other changes should target the latest versions/* branch.
  • the RELEASE_NOTES.md document in case of relevant feature or config changes.

@Falx Falx marked this pull request as ready for review March 4, 2022 08:39
@Falx Falx requested a review from joachimvh March 4, 2022 08:39
@Falx Falx changed the title Feat/content type params Feat: Store content type parameters Mar 4, 2022
Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the general idea, there are just some code changes that can simplify everything I think. Also the classes that currently parse the content-type should be updated (mentioned in one of the comments below).

src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/util/HeaderUtil.ts Outdated Show resolved Hide resolved
src/util/HeaderUtil.ts Outdated Show resolved Hide resolved
src/util/Vocabularies.ts Outdated Show resolved Hide resolved
@Falx Falx changed the base branch from main to versions/4.0.0 March 7, 2022 13:39
@Falx Falx force-pushed the feat/content-type-params branch 2 times, most recently from 12642b3 to 24935c2 Compare March 7, 2022 13:48
@Falx
Copy link
Contributor Author

Falx commented Mar 7, 2022

I've incorporated all changes discussed before.

@Falx Falx requested a review from joachimvh March 7, 2022 14:26
Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just some minor nitpicks. Some commits from the main branch also snuck in here.

src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/input/metadata/ContentTypeParser.ts Outdated Show resolved Hide resolved
src/util/FetchUtil.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
src/http/representation/RepresentationMetadata.ts Outdated Show resolved Hide resolved
@Falx Falx requested a review from joachimvh March 11, 2022 12:20
Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@joachimvh joachimvh merged commit a860205 into versions/4.0.0 Mar 14, 2022
@joachimvh joachimvh deleted the feat/content-type-params branch March 14, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants