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

Consider separating processMessage() into individual handling methods per DWN Interface Method #289

Closed
thehenrytsai opened this issue Mar 31, 2023 · 5 comments
Assignees
Labels
good first issue Good for newcomers hacktoberfest For the hacking month of October refactoring Code refactoring with no functional impact

Comments

@thehenrytsai
Copy link
Member

thehenrytsai commented Mar 31, 2023

Background:

With the introduction and implementation of RecordsRead (and other Interface Methods to follow like RecordsCommit), it is becoming apparent that the return type cannot be represented by a universal type that covers all need, unless we hack our way by adding a bunch of optional properties or even just use any.

Task Details:

  • Maybe the time has come for us to consider evolve processMessage() which has served well, and replace/augment it with individual handlers:

handleRecordsRead(...): RecordsReadResponse { ... }
handleRecordsWrite(...): RecordsWriteResponse { ... }
...

Objective:

  • create a handler for handleRecordsWrite(...): RecordsWriteResponse { ... }

handleRecordsRead(...): RecordsReadResponse { ... } was introduced in this pull request if you're interested in an example.

Picking Up This Issue:

  • If you'd like to work on this, please comment "picking this up" below, and I'll assign the issue to you

Questions:

Resources:

  • Creating a Pull Request: If you're new to GitHub and unsure how to create a pull request, follow this step-by-step guide.

Remember, communication is key! If you have any questions or face any challenges, we're here to help so please don't hesitate to reach out.

Good Luck! 🍁

@shobitb
Copy link
Contributor

shobitb commented Oct 2, 2023

@thehenrytsai / @EbonyLouis — can I pick this up?

If yes, a few questions before I get started —

  1. Do you think the response type for handleRecordsWrite can continue to be GenericMessageReply (like in the Handler)? Or introduce a new RecordsWriteReply (but that would essentially be a GenericMessageReply (hence, an alias))?
  2. Is it okay to introduce handleRecordsDelete (and any subsequent refactor) in separate commits? I feel tiny commits are easier to review/merge.

Looking forward to hearing back and contributing. Thanks!

@EbonyLouis
Copy link
Contributor

@shobitb yay, I assigned it to you!
I also reached out to Henry he'll be the best person to answer your question.

@thehenrytsai
Copy link
Member Author

Hi @shobitb, thanks for considering to contribute!! Answering your questions:

Do you think the response type for handleRecordsWrite can continue to be GenericMessageReply

No, the response type should be as specific to the type of message as possible, which is really the intent and benefit of having dedicated handler methods. There is a couple of precedence (RecordsRead and RecordsQuery) that you can follow.

Is it okay to introduce handleRecordsDelete (and any subsequent refactor) in separate commits?

Totally. Agree with you that small commits are better for many reasons!

Also, when making sure you have test coverage on these new dedicated handlers, you have one of the two approaches: either add new tests in dwn.spec.ts, or modify one (or a couple) existing tests to call these dedicated handlers instead. Obviously adding tests to dwn.spec.ts is more intentional, but I am not too opinionated if you prefer the latter/lazier approach.

shobitb added a commit to shobitb/dwn-sdk-js that referenced this issue Oct 6, 2023
This commit introduces a handleRecordsWrite function meant to be used in place of the existing processMessage which is eventually meant to be replaced as described in issue TBD54566975#289.

This commit also updates the relevant tests in records-(write|delete|read|query).ts files, which were using processMessage and replaces its usage with the new handleRecordsWrite.

It also introduces a few new tests in dwn.spec.ts, enough to bring uncovered lines of this function to 0 (more specifically, the new test is meant to cover the exception path).
@shobitb
Copy link
Contributor

shobitb commented Oct 6, 2023

Thanks for assigning and helping, @EbonyLouis and @thehenrytsai. I've created a PR. Would love your feedback. If this looks good, I'll use the same format to introduce handleRecordsDelete in a subsequent PR.

shobitb added a commit to shobitb/dwn-sdk-js that referenced this issue Oct 7, 2023
This commit introduces a handleRecordsDelete function meant to be used in place of the existing processMessage (which is eventually meant to be replaced, as described in issue TBD54566975#289).

This commit also updates the relevant tests in records-(write|delete|read).ts files, which were using processMessage and replaces its usage with the new handleRecordsDelete.

It also introduces a test in dwn.spec.ts, enough to bring uncovered lines of this new function to 0 (more specifically, the new test is meant to cover the exception path).
@diehuxx
Copy link

diehuxx commented Oct 13, 2023

#554 addresses this by overloading the function signature of processMessage, so we no longer need separate methods for better typing

@diehuxx diehuxx closed this as completed Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest For the hacking month of October refactoring Code refactoring with no functional impact
Projects
Status: Done
Development

No branches or pull requests

4 participants