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: rework resource store to return extra info #1350

Merged

Conversation

BelgianNoise
Copy link
Member

@BelgianNoise BelgianNoise commented Jun 24, 2022

πŸ“ Related issues

This PR is mostly based on work of @ixuz from #1075 .
Seemed like a good idea to branch of the current code as the linked PR is still based on v2.0.0 .

✍️ Description

(Copy from other PR)

Preparation for implementation of Solid Notifications according to https://solid.github.io/notifications/protocol
The proposal refers to https://www.w3.org/TR/activitystreams-core/ for the activity types.
In order to provide meaningful notifications to subscribers we have differentiated between the types of resource changes, such as CREATED, CHANGED and DELETED.

This PR is backwards compatible as it only changes internal behavior.

βœ… PR check list

Before this pull request can be merged, a core maintainer will check whether

  • this PR is labeled with the correct semver label
    • semver.patch: Backwards compatible bug fixes.
    • semver.minor: Backwards compatible feature additions.
    • semver.major: Breaking changes. This includes changing interfaces or configuration behaviour.
  • the correct branch is targeted. Patch updates can target main, other changes should target the latest versions/* branch.
  • the RELEASE_NOTES.md document in case of relevant feature or config changes.
  • any relevant documentation was updated to reflect the changes in this PR.

@BelgianNoise
Copy link
Member Author

BelgianNoise commented Jun 24, 2022

Original comment: #1075 (comment) .

I'd suggest a different design, namely:

  • Emit specific created, deleted, updated events, with the identifier of the resource as a parameter
  • Still also emit the changed event, with the identifier as a first parameter, and the kind of change as the second

That way:

  • The change mechanism keeps on working as-is, and listeners can keep on being interested in any change
  • Listeners can choose to only follow certain events

@RubenVerborgh Im not sure what you mean exactly.

If, for example, there are multiple identifiers that were updated: Do we want to emit an updated event for every identifier that was changed (indicated by SOLID_AS.Activity AS.Update) or only one updated event containing an object of type Record<string, RepresentationMetadata>.

@joachimvh
Copy link
Member

If, for example, there are multiple identifiers that were updated: Do we want to emit an updated event for every identifier that was changed (indicated by SOLID_AS.Activity AS.Update) or only one updated event containing an object of type Record<string, RepresentationMetadata>.

The first. But the comment of @ixuz below there seems to indicate that there were problems with that idea so I don't think it's relevant anymore?

@ixuz
Copy link
Member

ixuz commented Jun 27, 2022

If, for example, there are multiple identifiers that were updated: Do we want to emit an updated event for every identifier that was changed (indicated by SOLID_AS.Activity AS.Update) or only one updated event containing an object of type Record<string, RepresentationMetadata>.

The first. But the comment of @ixuz below there seems to indicate that there were problems with that idea so I don't think it's relevant anymore?

Looking back at this and my previous comment, since then I've changed my mind and think the first option is reasonable.

I recognize that some contextual information about the overall change may be lost(as each identifier is emitted individually), but on the other hand, we have not made use of that [extra contextual] information anyways in our other PR that leverages the feature of this PR. We can even see here that we're effectively breaking up the event into individual identifiers before passing to the next handler πŸ˜…

Let's go with the first option. πŸ‘

Co-authored-by: Anton Wiklund <ixuz07@gmail.com>
@BelgianNoise BelgianNoise requested a review from ixuz July 1, 2022 09:02
Copy link
Member

@ixuz ixuz left a comment

Choose a reason for hiding this comment

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

Great! Looks good to me! πŸ‘

@ixuz
Copy link
Member

ixuz commented Jul 1, 2022

Now I think this PR is ready for merge, please have another look @joachimvh
Thanks πŸ™‚

Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

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

No major changes requested, just some minor issues here and there. I did not read the comments/reviews above so if anything there was relevant to one of my comments do let me know.

One important note regarding the output type of the ResourceStore: in #1363 I introduce a Map that can safely use ResourceIdentifiers as keys to make sure the same objects get reused and to be future-proof if we ever extend what such an object contains. This should also be used as the output type of the ResourceStore here instead of the Record<string, RepresentationMetadata> currently used. So the interface would be a Map<ResourceIdentifier, RepresentationMetadata>. That PR is not merged yet though so you currently can't do that so keep using the records until then. Depending on which PR gets merged first it can either be added here or I'll just to a small PR myself afterwards to do the change as the changes for this should be quite minimal

RELEASE_NOTES.md Outdated Show resolved Hide resolved
documentation/resource-store.md Outdated Show resolved Hide resolved
src/storage/ResourceStore.ts Outdated Show resolved Hide resolved
src/storage/DataAccessorBasedStore.ts Outdated Show resolved Hide resolved
src/storage/DataAccessorBasedStore.ts Outdated Show resolved Hide resolved
src/http/ldp/PostOperationHandler.ts Outdated Show resolved Hide resolved
src/http/representation/ResourceIdentifier.ts Outdated Show resolved Hide resolved
src/storage/MonitoringStore.ts Outdated Show resolved Hide resolved
src/util/Vocabularies.ts Outdated Show resolved Hide resolved
test/unit/http/ldp/PostOperationHandler.test.ts Outdated Show resolved Hide resolved
this.emit('changed', identifier);
private emitChanged(changes: Record<string, RepresentationMetadata>): Record<string, RepresentationMetadata> {
for (const [ key, value ] of Object.entries(changes)) {
const activity = value.get(SOLID_AS.terms.Activity)?.value;
Copy link
Member

Choose a reason for hiding this comment

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

Just realized this is going to error if there are multiple values for Activity. It can also potentially send invalid values in case the source store set a wrong value there. There should probably be checks for these cases to make sure this store only emits correct values.

Copy link
Member

Choose a reason for hiding this comment

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

You might have missed this comment since I made it after the review. But thinking on this again we should take into account other people making faulty stores so this can be ignored.

@BelgianNoise
Copy link
Member Author

@joachimvh The CI seems bugged for me. It doesn't run and/or doesn't report. Could you take a look at that?

@joachimvh
Copy link
Member

@joachimvh The CI seems bugged for me. It doesn't run and/or doesn't report. Could you take a look at that?

It's because there is a merge conflict. The structure of the documentation folder changed recently so this will have to be modified in this PR.

Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

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

Just some minor refactor comments but then this should be ready to merge

documentation/markdown/resource-store.md Outdated Show resolved Hide resolved
src/storage/ResourceStore.ts Outdated Show resolved Hide resolved
this.emit('changed', identifier);
private emitChanged(changes: Record<string, RepresentationMetadata>): Record<string, RepresentationMetadata> {
for (const [ key, value ] of Object.entries(changes)) {
const activity = value.get(SOLID_AS.terms.Activity)?.value;
Copy link
Member

Choose a reason for hiding this comment

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

You might have missed this comment since I made it after the review. But thinking on this again we should take into account other people making faulty stores so this can be ignored.

Copy link
Member

@joachimvh joachimvh left a comment

Choose a reason for hiding this comment

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

Thanks. I assume the plan is to now look at the notifications spec?

@joachimvh
Copy link
Member

joachimvh commented Jul 6, 2022

@BelgianNoise apparently there is still a conflict, can you look into what it is?

Edit: you can ignore this, I was looking at the wrong setting.

@joachimvh joachimvh merged commit e0954cf into versions/5.0.0 Jul 6, 2022
@joachimvh joachimvh deleted the feat/rework-resource-store-to-return-extra-info branch July 6, 2022 12:40
@ixuz
Copy link
Member

ixuz commented Jul 6, 2022

Thanks. I assume the plan is to now look at the notifications spec?

Indeed that's the next step in our plan πŸ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver.major Requires a major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants