holochain / scaffolding

Scaffolding tool to quickly generate and modify holochain applications
https://docs.rs/holochain_scaffolding_cli
220 stars 19 forks source link

spike: Improve the quality/ readability of generated validation rust code #390

Open c12i opened 1 month ago

c12i commented 1 month ago

Goals

mattyg commented 1 week 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