Skip to content

feat: Take preferences as input in RepresentationConvertingStore - #1469

Merged
jvherweg merged 1 commit into
versions/6.0.0from
feat/converting-preferences
Jan 11, 2023
Merged

jvherweg merged 1 commit into
versions/6.0.0from
feat/converting-preferences

Conversation

@jvherweg

@jvherweg jvherweg commented Oct 5, 2022

Copy link
Copy Markdown
Member

📁 Related issues

Closes #297

✍️ Description

Apparently this is possible now (and probably was for some time), although the configuration is less pretty.

The metadataStrategy field is because of f7742cf

@jvherweg
jvherweg requested a review from RubenVerborgh October 5, 2022 13:59
@jvherweg
jvherweg force-pushed the feat/converting-preferences branch from ed3a0c9 to c0bdcac Compare October 5, 2022 14:34

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that works—but what's the use case? I see our configs only have fixed wishes.
Or is this for symmetry?

Note that we might inPreferences?: RepresentationPreferences | string and support both; at least if Components.js does (I think it wouldn't). Or just keep inType too. Or not. I'm happy either way.

super(source);
this.metadataStrategy = metadataStrategy;
const { inConverter, outConverter, inType } = options;
const { inConverter, outConverter, inPreferences } = options;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we swap this line with the one above please 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is unclear to me which two lines you want swapped. Could you make a change suggestion as usual?

Comment on lines +25 to +29
* @param source - Source store to get data from.
* @param metadataStrategy - Used to identify metadata resources as those always need to be converted.
* @param options - `outConverter` converts data returned by the store,
* `inConverter` converts incoming data,
* `inPreferences` determines how incoming data should be converted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a hard time remembering what this parameter means, and the text doesn't sufficiently help. Is there any clearer description possible?

Maybe "incoming" and "outcoming" are too vague. Do we mean data retrieved from the store, and data passes to the store?

Suggested change
* @param source - Source store to get data from.
* @param metadataStrategy - Used to identify metadata resources as those always need to be converted.
* @param options - `outConverter` converts data returned by the store,
* `inConverter` converts incoming data,
* `inPreferences` determines how incoming data should be converted.
* @param source - Store we retrieve data from and send data to.
* @param metadataStrategy - Used to distinguish regular resources (which may be converted) from metadata resources a (which always need conversion).
* @param options.outConverter Converts data retrieved from the source store
* @param options.inConverter Converts data passed to the source store
* @param options.inPreferences The preferred input format for the source store, as passed to the inConverter

Still unsure why metadata always needs to be converted; isn't that specific to some configs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(It is interesting to see how time changes things 😄 #279 (comment) )

Yes, incoming data = data from an HTTP request that we receive = data being sent to the resource store (e.g., if the backend is a SPARQL data accessor, we want to convert all incoming data into quads), and outcoming data = data we send in the response = data received from the store (so content negotiation).

Still unsure why metadata always needs to be converted; isn't that specific to some configs?

Relevant comment (although I'm not sure how well this will load with how large that PR is): #1188 (comment)

The issue was that the DataAccessorBasedStore was taking a converter as input so it could convert the input for metadata resources to quads so it could store them in a RepresentationMetadata. It was then changed to doing it in this store instead since it specifically already had the job of converting incoming data for later stores.

Having looked at it again, I also have been thinking that this might not be flexible enough though. The alternative, more flexible, solution would be to create a new ResourceStore that converts incoming metadata to quads. This way that store can be removed again if someone has a ResourceStore solution where this step is not needed. Or to be even more flexible, what I'm currently thinking of:

  • RepresentationConvertingStore has an extra (optional) input inValidator, which is an InputValidator (better name pending).
  • InputValidator takes the identifier/representation as input and outputs a boolean.
  • MetadataInputValidator returns true if the target is a metadata identifier.
  • The RepresentationConvertingStore only applies the inConverter on inputs that return true on the validator.
  • Might even take a list of validators as input so you can have different preference/validator combinations.

But that would be better suited for a different PR though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The alternative, more flexible, solution would be to create a new ResourceStore that converts incoming metadata to quads.

Made me wonder if metadata could be (conceptually) a different store, which is then a different wrapper around the internal store.

But yes, all out of scope for this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

slightly modified from @RubenVerborgh's suggestion

Suggested change
* @param source - Source store to get data from.
* @param metadataStrategy - Used to identify metadata resources as those always need to be converted.
* @param options - `outConverter` converts data returned by the store,
* `inConverter` converts incoming data,
* `inPreferences` determines how incoming data should be converted.
* @param source — Store we retrieve data from and send data to.
* @param metadataStrategy — Used to distinguish regular resources (which may be converted) from metadata resources (which always need conversion).
* @param options.outConverter — Converts data after retrieval from the source store
* @param options.inConverter — Converts data before passing to the source store
* @param options.inPreferences — The preferred input format for the source store, as passed to the inConverter

@jvherweg

Copy link
Copy Markdown
Member Author

Yes, that works—but what's the use case? I see our configs only have fixed wishes.
Or is this for symmetry?

Flexibility mostly. This was something that was suggested when this class was originally made but couldn't be done because Components.js didn't allow it. And I wanted to fix some smaller issues after having just done a large PR.

@jvherweg
jvherweg force-pushed the feat/converting-preferences branch 3 times, most recently from b67aedc to 510077a Compare January 11, 2023 14:42
@jvherweg
jvherweg force-pushed the feat/converting-preferences branch from 510077a to dd0c849 Compare January 11, 2023 14:48
@jvherweg
jvherweg merged commit 7422fbf into versions/6.0.0 Jan 11, 2023
@jvherweg
jvherweg deleted the feat/converting-preferences branch January 11, 2023 15:03
@TallTed

TallTed commented Jan 11, 2023

Copy link
Copy Markdown
Contributor

@joachimvh -- Were the change requests/suggestions applied before merge? Or are they being silently ignored/rejected?

@jvherweg

Copy link
Copy Markdown
Member Author

@joachimvh -- Were the change requests/suggestions applied before merge? Or are they being silently ignored/rejected?

They were added:

* @param source - Store we retrieve data from and send data to.
* @param metadataStrategy - Used to distinguish regular resources (which may be converted)
* from metadata resources (which always need conversion).
* @param options - Determines when data should be converted.
* * outConverter: Converts data after retrieval from the source store.
* * inConverter: Converts data before passing to the source store.
* * inPreferences: The preferred input format for the source store, as passed to the inConverter.

(Although I did a minor refactor to prevent TSDoc warnings by making sure the @param values match the actual parameters).

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