Repository navigation
feat: Interface Model Support after Refactor - #3292
BenAuerDev wants to merge 29 commits into
Conversation
SandPod
left a comment
There was a problem hiding this comment.
Nice work getting this feature into the code 🚀
There is still some massaging left that needs to be done before this is ready for production and test covered to ensure future devs doesn't break it.
| @@ -0,0 +1,4 @@ | |||
| exception: ExceptionWithInterface | |||
There was a problem hiding this comment.
Suggestion: Add coverage for all cases listed below:
- Model that inherits from multiple interfaces
- Model that inherits from interface that inherits from another interface
For the model that inherits from multiple interfaces it would be good if the interfaces have a name collisions for one of the fields but it is the same type (should be OK).
There was a problem hiding this comment.
Good point, I'll add this last again :)
|
Nice progress! I mostly checked the comments that you had resolved and try to answer any open questions. Let me know when it is ready for a full review again :) |
f4c12d0 to
757f788
Compare
|
I rebased the branch. Only the last 3 commits are new |
SandPod
left a comment
There was a problem hiding this comment.
Seems like there are comments that have not been submitted (by me) and some comments that have not been addressed.
Please have a look again and remember to expand the comments section when inspecting the PR.
| SourceSpanSeverityException( | ||
| 'Conflicting types for field "${entry.key}" in implemented interfaces: $type vs ${field.type.className}', | ||
| span, | ||
| ), |
There was a problem hiding this comment.
Suggestion: Please add a test that validates this.
I couldn't find a test where this is validated.
There was a problem hiding this comment.
in implements_test.dart line 418 :)
| ValidateNode( | ||
| Keyword.parent, | ||
| isDeprecated: true, | ||
| isRemoved: true, | ||
| alternativeUsageMessage: | ||
| 'Use the relation keyword instead. E.g. relation(parent=parent_table). Note that the default onDelete action changes from "Cascade" to "NoAction" when using the relation keyword.', | ||
| ), | ||
| ValidateNode( |
There was a problem hiding this comment.
Yes! This should be a "top" level keyword, that should be required to be set in order for these "table" specific keywords to be used.
The required logic can be added to the validateRelationKey logic.
| ValidateNode( | ||
| Keyword.parent, | ||
| isDeprecated: true, | ||
| isRemoved: true, | ||
| alternativeUsageMessage: | ||
| 'Use the relation keyword instead. E.g. relation(parent=parent_table). Note that the default onDelete action changes from "Cascade" to "NoAction" when using the relation keyword.', | ||
| ), | ||
| ValidateNode( |
There was a problem hiding this comment.
This does not seem to have been resolved.
757f788 to
7430144
Compare
|
Did another rebase, to be up to date with the latest changes on |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
definitions: 1. Add `ImplementsDefinition`s (incl. unresolved and resolved) with doc comments 2. Add comments to `InheritanceDefinition`s to make it easier to distinguish from `ImplementsDefinition`s without looking up. 3. Add `InterfaceClassDefinition` 4. Modify `ClassDefinition`: - add field `isImplementing` - add getter `implementedInterfaces` - add getter `implementedFields` - add getter `uniqueImplementedFields` - add getter `fieldsIncludingImplemented` 5. Modify `ModelClassDefintion`: - pass `isImplementing` to super - add getter `allFields` (inherited, implemented, own) entity_dependency_resolver: add `_resolveImplements` model_analyzer: add `InterfaceClass` to analyzer model_parser: 1. add `serializeInterfaceClassFile` 2. add `parseIsImplementing` keywords: add `interfaceType` and `isImplementing` to keywords restrictions: 1. add restrictions to validate `InterfaceNames` 2. add restrictions to dissallow redefining a implementedField without default value class_yaml_definition and exception_yaml_definition: add `ValidateNode` for `IsImplementing` interface_yaml_definition: add `InterfaceYamlDefinition` for analyzer extra_properties_test, inheritance_test and model_types_test: update tests returning a set of white listed node names as `interface` is now a white listed interface_test: test `analyzer` and `restrictions`
model_library_generator: 1. add logic to generate a InterfaceClass 2. add logic to handle implementing interfaces 3. update logic handling fields 4. add logic to apply the `override` annotation to fields from implemented interfaces model_class_definition_builder: add `isImplementing` with setter exception_class_definition_builder: add `isImplementing` and `withSimpleField` interface_class_definition_builder: create class to test `InterfaceClasses` compilation_unit_helpers: add `tryFindImplementedClass` for tests interface_class_test: add test for generating interface classes
similar to the sealed classes, we don't serialize `interfaces` in `library_generator` I renamed unsealedModels => serializableModels and added a rule that excludes `InterfaceClassDefinition`s
…rverpod test project
…lementsDefinition
I forgot to remove that after copying the setup
…ve boolean for _buildModelClassConstructor
…ields and update doc comment
…ning new scope, or any relation
…ype and add tests validating duplicated fields and implementing interfaces from another module
5127c63 to
37c041f
Compare
|
I did a rebase but couldn't activate the local cli to regenerate the files with conflicts yet edit: I managed to fix what I lost in the rebase and generate the protocol. Now only two tests are failing, I feel this is because the additional validation I added for interface support somehow changes the order in which the classes are validated. 🤔 |
This PR enables the user to declare
interfaces and classes that use theimplementskeyword to implement them.It's a newer version of #3248 after #3270 came with a refactor that split
ClassDefinitionto be a baseclass that is extended byModelClassDefinitionandExceptionClassDefinition. Therefore I addedInterfaceClassDefinitionand wrote the generation logic accordingly 🚀This is done in 4 steps/commits:
The changes are closer described in each commit message
This PR tries to close #2842
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
No breaking changes.