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

Event and Records Subscriptions #607

Closed
wants to merge 16 commits into from
Closed

Conversation

LiranCohen
Copy link
Member

@LiranCohen LiranCohen commented Nov 14, 2023

Working off of the work @andorsk put in for Subscriptions, #508.

I re-worked it to match our current scopes and the way we handle permissions.

This PR adds 2 new interfaces EventsSubscribe and RecordsSubscribe.

EventsSubscribe will follow the current authorization for EventsGet and the one that is coming for EventsQuery, that is only tenant is currently authorized for it, without any grants/delegation. This will come in a separate PR.

RecordsSubscribe follows the authorization/delegation rules from RecordsQuery at the moment, and builds up match filters for the EventStream in the same way that it builds up filters for the MessageStore when retrieving messages.

There are still many missing tests, I am considering moving some of the tests from RecordsQuery into scenario testing where we can test both Query and Subscribe together.

Some things to note:
Current approach for re-authorization are TTL based to re-authorize the original subscription message, in a future PR we could purge the subscription upon receipt of a PermissionsRevoke or a RecordsDelete associated with a protocol role. I am open to ripping out re-authorization completely from this PR in favor of doing that approach in a subsequent PR.

Also I overloaded the the subscribe method on the interface in order to be able to have more defined behaviors and objects around the individual types of subscriptions. I'm personally 50/50 on keeping this abstraction as they are very similar. The only difference currently is that the RecordsSubscribe handler will type the messages it produces as either RecordsWriteMessage or RecordsDeleteMessage where as the EventsSubscribe will emit a GenericMessage.

Copy link

codesandbox bot commented Nov 14, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2023

Codecov Report

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

Comparison is base (fb71bfa) 98.83% compared to head (2b23061) 98.54%.

Files Patch % Lines
src/event-log/event-stream.ts 87.71% 14 Missing ⚠️
src/handlers/records-subscribe.ts 96.21% 11 Missing and 1 partial ⚠️
src/core/records-grant-authorization.ts 82.85% 6 Missing ⚠️
src/handlers/events-subscribe.ts 91.66% 6 Missing ⚠️
src/dwn.ts 98.88% 1 Missing ⚠️
src/interfaces/events-subscribe.ts 98.46% 1 Missing ⚠️
src/interfaces/records-subscribe.ts 99.08% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #607      +/-   ##
==========================================
- Coverage   98.83%   98.54%   -0.29%     
==========================================
  Files          71       78       +7     
  Lines        9255    10253     +998     
  Branches     1391     1506     +115     
==========================================
+ Hits         9147    10104     +957     
- Misses        100      140      +40     
- Partials        8        9       +1     

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

"type": "object",
"additionalProperties": false,
"required": [
"descriptor"
Copy link
Member

Choose a reason for hiding this comment

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

Sanity: authorization is required also no?

"type": "object",
"additionalProperties": false,
"required": [
"descriptor"
Copy link
Member

Choose a reason for hiding this comment

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

Sanity: authorization is required also no?

@LiranCohen
Copy link
Member Author

Closing this in favor of 2 separate PRs for Records + Events Subscribe.

#658
#659

@LiranCohen LiranCohen closed this Jan 10, 2024
@LiranCohen LiranCohen deleted the lirancohen/subscriptions branch March 6, 2024 19:50
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