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

Implemented non-RDF fetch #104

Merged
merged 11 commits into from
Jun 3, 2020
Merged

Implemented non-RDF fetch #104

merged 11 commits into from
Jun 3, 2020

Conversation

NSeydoux
Copy link
Contributor

New feature description

This PR adds a new function exposing a high-level feature to fetch non-RDF data, while using the internal fallback fetch.

Checklist

  • All acceptance criteria are met.
  • Relevant documentation, if any, has been written/updated.
  • The changelog has been updated, if applicable.
  • New functions/types have been exported in index.ts, if applicable.
  • Commits in this PR are minimal and have descriptive commit messages.

@NSeydoux NSeydoux requested review from Vinnl and pmcb55 May 27, 2020 08:25
Copy link
Contributor

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

Some small typo and style suggestions inline, and a couple of questions as food for thought, but I tested this locally and it works flawlessly :)

image

(That's an image, shown on the page, after having been fetched from my Pod, where it is set to private.)

src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.test.ts Show resolved Hide resolved
src/nonRdfData.ts Outdated Show resolved Hide resolved
src/nonRdfData.ts Outdated Show resolved Hide resolved
src/nonRdfData.ts Outdated Show resolved Hide resolved
@NSeydoux NSeydoux force-pushed the feat/74-read-non-rdf-data branch 2 times, most recently from 16d38b8 to eb29a5f Compare June 2, 2020 08:32
@Vinnl
Copy link
Contributor

Vinnl commented Jun 2, 2020

Ah btw, I just realised that what I didn't test is whether this actually works with solid-auth-fetcher as well. Given that that was explicitly one of Kevin's concerns, probably good to do that :P Did you happen to have given that a try?

@NSeydoux
Copy link
Contributor Author

NSeydoux commented Jun 2, 2020

I did, but for unauthenticated fetches only, because it works directly in command line, which is convenient as opposed to a full-blown webapp where a little more configuration is required. I have been playing around with small webapps yesterday for practice, but they use the @solid/react components which currently have an issue with solid-auth-fetcher. I'll create a plain web app to test this.

@NSeydoux
Copy link
Contributor Author

NSeydoux commented Jun 2, 2020

Good news: with @inrupt/solid-auth-fetcher@0.0.6, it works.

Copy link
Contributor

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

Added one new comment for consideration, and two remarks w.r.t. the new changes. There are also a number of conversations that are marked as resolved, even though I don't see either the suggested changes or a response about why they do not apply?

@@ -60,6 +61,7 @@ import {
// These tests aren't too useful in preventing bugs, but they work around this issue:
// https://github.com/facebook/jest/issues/10032
it("exports the public API from the entry file", () => {
expect(getFile).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh huh, seeing these two next to each other, I'm starting to wonder whether we shouldn't actually call it fetchFile for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that there is going to be a deleteFile and a createFile, and getFile is meant to only support a GET request, so fetchFile may sound a little too generic for people used to the fetch API being a gateway to all HTTP requests. However, given that we use fetch for the 'retrieve' operation everywhere, you are right, this would be more consistant. I'll make the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that's a good point - shouldn't there be equivalent methods for LitDatasets? Given the "Planned API" page, it seems that createFile would be saveFile (or saveLitDataset would be createLitDataset - though maybe that doesn't cover that it could also overwrite existing datasets, just like (I presume) createFile could overwrite existing files?), and that we haven't thought of having a deleteLitDataset yet - which I presume we should have? (And which is probably an alias of deleteFile or vice versa.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I didn't think about the overwriting of existing files. I think saveFile would be good, and we can discuss the exact behaviour in the appropriate PR/ticket.

Copy link
Contributor Author

@NSeydoux NSeydoux Jun 3, 2020

Choose a reason for hiding this comment

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

And adding a deleteLitDataset seems to be something that we should plan. Also, 1b56737 changes getFile into fetchFile

Comment on lines 20 to 26
init: Partial<GetFileOptions> = defaultGetFileOptions
): Promise<Response> {
const config = {
...defaultGetFileOptions,
...init,
};
// The `fetch` field is not part of the original RequestInit, and it is no longer
// needed in the init object.
delete init.fetch;
return config.fetch(input, init);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd go for separate the options specific to getFile from the options passed to fetch, rather than explicitly deleting non-fetch options, e.g.:

Suggested change
init: Partial<GetFileOptions> = defaultGetFileOptions
): Promise<Response> {
const config = {
...defaultGetFileOptions,
...init,
};
// The `fetch` field is not part of the original RequestInit, and it is no longer
// needed in the init object.
delete init.fetch;
return config.fetch(input, init);
options: Partial<GetFileOptions> = defaultGetFileOptions
): Promise<Response> {
const config = {
...defaultGetFileOptions,
...options,
};
return config.fetch(input, config.init);

Otherwise, every option ever added to getFile will also require adding another delete statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Fixed in d1a2fc8


expect(mockFetch.mock.calls).toEqual([["https://some.url", {}]]);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should also have a test that checks that the Response is actually returned to the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ee40efb

@NSeydoux
Copy link
Contributor Author

NSeydoux commented Jun 3, 2020

Good catch about the resolutions ! I think one of the commits in the suggestion batch had an issue (it did not introduce changes), and it messed up the whole batch.

Comment on lines 19 to 20
init?: RequestInit,
options: Partial<GetFileOptions> = defaultGetFileOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, sorry to keep going on about this, but given that init is optional, wouldn't it be better as a property on options (i.e. options.init)? Because now if you want to pass a different fetch (or a different option that's added in the future) but not a different init, you'd have to do fetchFile('https://some.url', undefined, { fetch: fetch }).

Suggested change
init?: RequestInit,
options: Partial<GetFileOptions> = defaultGetFileOptions
init?: RequestInit,
options: Partial<GetFileOptions> = defaultGetFileOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't worry, I was hesitant in the implementation exactly for this reason :). Fixed in c676f1c

src/nonRdfData.test.ts Outdated Show resolved Hide resolved
src/nonRdfData.ts Outdated Show resolved Hide resolved
NSeydoux and others added 11 commits June 3, 2020 17:34
getFile fetches a data blob, and returns it to the user. It uses the underlying fallback fetch, and supports content negociation by allowing the user to pass in headers.
Co-authored-by: Vincent <Vinnl@users.noreply.github.com>
In order to not require a documentation additional to the fetch API's, the non-RDF fetching will be closer to the original fetch.
Co-authored-by: Vincent <Vinnl@users.noreply.github.com>
@NSeydoux NSeydoux merged commit 25deaa9 into master Jun 3, 2020
@NSeydoux NSeydoux deleted the feat/74-read-non-rdf-data branch June 3, 2020 15:46
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