Repository navigation
feat: Take preferences as input in RepresentationConvertingStore - #1469
Conversation
ed3a0c9 to
c0bdcac
Compare
RubenVerborgh
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Can we swap this line with the one above please 🙂
There was a problem hiding this comment.
It is unclear to me which two lines you want swapped. Could you make a change suggestion as usual?
| * @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. |
There was a problem hiding this comment.
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?
| * @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?
There was a problem hiding this comment.
(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:
RepresentationConvertingStorehas an extra (optional) inputinValidator, which is anInputValidator(better name pending).InputValidatortakes the identifier/representation as input and outputs a boolean.MetadataInputValidatorreturns true if the target is a metadata identifier.- The
RepresentationConvertingStoreonly applies theinConverteron 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
slightly modified from @RubenVerborgh's suggestion
| * @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 |
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. |
b67aedc to
510077a
Compare
510077a to
dd0c849
Compare
|
@joachimvh -- Were the change requests/suggestions applied before merge? Or are they being silently ignored/rejected? |
They were added: CommunitySolidServer/src/storage/RepresentationConvertingStore.ts Lines 25 to 31 in 7422fbf (Although I did a minor refactor to prevent TSDoc warnings by making sure the |
📁 Related issues
Closes #297
✍️ Description
Apparently this is possible now (and probably was for some time), although the configuration is less pretty.
The
metadataStrategyfield is because of f7742cf