Open c12i opened 1 month ago
My vague idea is that we could have a ValidateEntry
trait that you implement for each entry type. The ValidateEntry
trait has a few functions validate_create
, validate_update
, validate_delete
which by default return ValidateCallbackResult::Valid
(or don't have a default implementation if we want to force app devs to be explicit).
Then we do some refactoring of the Op transformation such that we can just run the validate function for that entry type with the provided data.
For LinkTypes, rust doesn't allow enum variants to impl traits so we might have to come up with some workaround - either a change to the hdk for how you define a LinkType, or something at the app level to associate a linktype variant to a trait implementation.
I know this is vague and definitely would need an exploratory spike to feel it out. But I think this could be ideal -- if it worked then scaffolding and app devs may never have to touch the validate callback, and can just implement this trait for their entry & link types.
I started playing with such a spike a while back and didn't get very far (it is half-baked and does not compile), but maybe the source code can give you some idea of what I'm hoping for: https://github.com/mattyg/forum-example-android-build-ci/commit/df51808643c47fcfc6eb048e5cc70b5b335d0efb#diff-c97ee58a611be9db354b14901907057f063e14c498e3c1748185367ba231095b
Goals
Explore the possibility of using declarative macros to reuse a lot of repeated code
Firstly, identify instances of repeated code in the validation logic and identify code that can be grouped into a single macro