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!: improve file client implementation #1175

Merged
merged 9 commits into from
Dec 1, 2023

Conversation

JKRhb
Copy link
Member

@JKRhb JKRhb commented Nov 28, 2023

As a spinoff from #1166, this PR extends the file client implementation with support for the writeproperty operation and improves the handling of file:// URLs. As the determination of the Content-Type from the file extension was somewhat deviating from the standard (as this ignored the default Content-Type implied by a TD form), I removed it.

This last aspect might be a bit controversial, but I think this should be the better approach to have an implementation that is extendable with additional Content-Types by users who can simply register them with the ContentSerdes. However, I looking forward to feedback not only in this regard :)

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (0a6463b) 76.33% compared to head (5bdcb7c) 76.66%.
Report is 1 commits behind head on master.

Files Patch % Lines
packages/binding-file/src/file-client.ts 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1175      +/-   ##
==========================================
+ Coverage   76.33%   76.66%   +0.33%     
==========================================
  Files          80       80              
  Lines       16827    16813      -14     
  Branches     1616     1618       +2     
==========================================
+ Hits        12845    12890      +45     
+ Misses       3952     3893      -59     
  Partials       30       30              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JKRhb JKRhb marked this pull request as draft November 28, 2023 15:10
@JKRhb JKRhb marked this pull request as ready for review November 28, 2023 16:02
@JKRhb
Copy link
Member Author

JKRhb commented Nov 28, 2023

Had to apply some Windows-related fixes, the PR should now be ready for review :)

Copy link
Member

@danielpeintner danielpeintner left a comment

Choose a reason for hiding this comment

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

LGTM.

Added 2 comments...

packages/binding-file/test/.gitignore Show resolved Hide resolved
packages/binding-file/src/file-client.ts Outdated Show resolved Hide resolved
Copy link
Member

@relu91 relu91 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 just minor comments below. I would wait before merging for the point that Daniel made on the .gitignore.

@@ -92,7 +92,7 @@ servient.addClientFactory(new FileClientFactory(null));

let wotHelper = new Helpers(servient);
wotHelper
.fetch("file://TD.jsonld")
.fetch("file:///TD.jsonld")
Copy link
Member

Choose a reason for hiding this comment

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

Should we change this example using the new official requestThingDescription function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I would probably add that to #1166, though, alongside the rest of the file-related implementation of the new method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, okay, nevermind, as #1166 got already merged ;) Then I will add it to this PR instead :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an initial update of the example in 1b79e91, haven't tested it yet, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I now performed some tests and actually found a few bugs which I fixed in 3793b6e.

return new Content(contentType, resource);
}

public async readResource(form: Form): Promise<Content> {
const filePath = fileURLToPath(form.href);
const contentType = form.contentType ?? ContentSerdes.DEFAULT;
Copy link
Member

Choose a reason for hiding this comment

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

I know this is correct behavior, but it might be error-prone... people will try to serve files without expressing the content-type thinking that the client could figure it himself. Anyhow, just a comment no action is required here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a debug comment "saying that"... a la
... no contentType set, picked JSON by default

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried to incorporate this in 14c1780, let me know if that works for you :)

In general, I was wondering if we should maybe move the default Content-Type determination to the Form class (maybe as part of a get method) to have a consistent behavior across the codebase. I would make an initial proposal in a follow-up PR that we could discuss there if that's okay for you.

packages/binding-file/test/.gitignore Show resolved Hide resolved
Copy link
Member

@relu91 relu91 left a comment

Choose a reason for hiding this comment

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

Good to go now

@JKRhb JKRhb merged commit 8761e64 into eclipse-thingweb:master Dec 1, 2023
12 checks passed
@JKRhb JKRhb deleted the fix-file-client branch December 1, 2023 16:49
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