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

Fix TriG documents not being PUT-able #773

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Fix TriG documents not being PUT-able #773

merged 1 commit into from
Jul 28, 2021

Conversation

rubensworks
Copy link
Contributor

A temporary fix until a more generic solution is implemented (#768).

src/util/ContentTypes.ts Show resolved Hide resolved
src/storage/mapping/ExtensionBasedMapper.ts Outdated Show resolved Hide resolved
src/storage/mapping/ExtensionBasedMapper.ts Outdated Show resolved Hide resolved
@joachimvh
Copy link
Member

The reason the integration tests failed is because it also needs to be added in https://github.com/solid/community-server/blob/main/templates/config/filesystem.json .

The templates for dynamic pods don't fully make use of the new configuration setup yet so there's some duplication there.

@rubensworks
Copy link
Contributor Author

Amended the commit with all suggested changes.

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

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

Great, let's get the duplication out though. Can be a new issue as far as I'm concerned.

public constructor(
base: string,
rootFilepath: string,
overrideTypes: Record<string, string> = { acl: TEXT_TURTLE, meta: TEXT_TURTLE, trig: APPLICATION_TRIG },
Copy link
Member

Choose a reason for hiding this comment

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

Let's drop the default here—or leave it as it was.

The rationale is the following.

This class is expected to perform a "perfect" mapping from extensions to MIME types, with the (sole) exception of Solid-specific MIME types. So acl and meta are special in the sense that they do not exist outside of the Solid world. In contract, trig exists outside of Solid; it's basically a "bug" in mime-types (can we PR?).

Copy link
Member

Choose a reason for hiding this comment

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

According to the docs it uses the db here and they accept PRs https://github.com/jshttp/mime-db

application/trig is a content-type they recognize as existing, but it does not have an official extension associated with it in the db is the issue, as it does not have any in the official databases this library makes use of.

Copy link
Member

Choose a reason for hiding this comment

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

I maybe wonder whether we want to rename overrideTypes into customTypes perhaps.

Copy link
Member

Choose a reason for hiding this comment

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

src/storage/mapping/ExtensionBasedMapper.ts Outdated Show resolved Hide resolved
},
{
"SubdomainExtensionBasedMapper:_overrideTypes_key": "trig",
"SubdomainExtensionBasedMapper:_overrideTypes_value": "application/trig"
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps comment that this is a bug/omission in mime-types? (see below)

@@ -36,7 +36,7 @@ export class SubdomainExtensionBasedMapper extends ExtensionBasedMapper {
private readonly baseParts: { scheme: string; rest: string };

public constructor(base: string, rootFilepath: string, baseSubdomain = 'www',
overrideTypes = { acl: TEXT_TURTLE, meta: TEXT_TURTLE }) {
overrideTypes: Record<string, string> = { acl: TEXT_TURTLE, meta: TEXT_TURTLE, trig: APPLICATION_TRIG }) {
Copy link
Member

Choose a reason for hiding this comment

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

I definitely do not like this duplication here. Let's export this object from ./../util/ContentTypes?
Then I also have no objection for using it as the default in ExtensionBasedMapper above.

Copy link
Member

Choose a reason for hiding this comment

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

We could also just remove the default values from the constructor actually since they're in the config anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but the problem is that these values need to be encoded multiple times in config.

"ExtensionBasedMapper:_overrideTypes_key": "trig",
"ExtensionBasedMapper:_overrideTypes_value": "application/trig"
}
]
Copy link
Member

Choose a reason for hiding this comment

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

Here's me wishing that the object could be reused across subdomain.json and suffix.json, but I understand why that is currently not possible. Future idea for Components.js to have generic key/value props?

@RubenVerborgh RubenVerborgh removed their assignment Jun 13, 2021
@rubensworks
Copy link
Contributor Author

So I guess this PR can just be replaced with a version bump of mime-db once the change in jshttp/mime-db#238 is included in a next release.
If so, let's put this once on hold until then.

@RubenVerborgh
Copy link
Member

I have pinged jshttp/mime-db#238

@RubenVerborgh
Copy link
Member

this PR can just be replaced

I do like the genericness of the solution though; would still keep it and its tests, just not the .trig fix.

@RubenVerborgh RubenVerborgh marked this pull request as draft July 5, 2021 08:37
@RubenVerborgh RubenVerborgh added this to the v1.0.0 milestone Jul 5, 2021
@RubenVerborgh
Copy link
Member

Might need the override system in any case; .ts is not TypeScript at the moment, for instance.

@RubenVerborgh
Copy link
Member

A new version of the MIME library has been released, so we can adjust this PR.

Note that I'd still like to keep the option of having overrides.

@RubenVerborgh
Copy link
Member

@rubensworks But feel free to pass this on to anyone else; just so we have a champion to bring this to v1.0.0.

@rubensworks
Copy link
Contributor Author

Since mime-db is updated, the scope of this PR doesn't really align with my use case anymore, so not sure when I'll be able to look into this.
If it's urgent for the 1.0.0 release, perhaps @joachimvh is willing to take this up?

@joachimvh
Copy link
Member

If it's urgent for the 1.0.0 release, perhaps @joachimvh is willing to take this up?

Sure

@joachimvh joachimvh assigned joachimvh and unassigned rubensworks Jul 27, 2021
@joachimvh
Copy link
Member

A new version of the MIME library has been released, so we can adjust this PR.

The mime-types library also has to be updated to use the updated version of mime-db.

Or we can use the mime-db dependency directly and implement the wanted behaviour ourselves.

@RubenVerborgh
Copy link
Member

The mime-types library also has to be updated to use the updated version of mime-db.

Just a package-lock upgrade is fine with me.

@joachimvh joachimvh force-pushed the fix/put-trig branch 2 times, most recently from 4424375 to 6589c13 Compare July 27, 2021 14:47
@joachimvh
Copy link
Member

I have updated the commit. Now it is no longer necessary to set the defaults custom types in the config.

Trig is still in there since mime-types hardcodes its dependency in the package.json: https://github.com/jshttp/mime-types/blob/2.1.31/package.json#L17 . We can leave this open until that gets updated, is only a small change afterwards.

Using both mime functions for consistency. Not using the maps since mime.extensions stores arrays instead of best matches.

@joachimvh joachimvh marked this pull request as ready for review July 27, 2021 14:48
@@ -11,3 +12,6 @@ export const TEXT_TURTLE = 'text/turtle';
export const INTERNAL_ALL = 'internal/*';
export const INTERNAL_QUADS = 'internal/quads';
export const INTERNAL_ERROR = 'internal/error';

// Trig can be removed once the mime-types library is updated with the latest mime-db version
export const DEFAULT_CUSTOM_TYPES = { acl: TEXT_TURTLE, meta: TEXT_TURTLE, trig: APPLICATION_TRIG };
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps separate by newlines for easier access?

@rubensworks
Copy link
Contributor Author

rubensworks commented Jul 30, 2021

@joachimvh FYI, It looks like mime-types has been updated to 2.1.32, which includes the new mime-db.

Edit: created a PR for it in #882

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.

None yet

3 participants