feat: added type aliases for reflect kinds to provide a single access point#49
Merged
Akalanka47000 merged 2 commits intomainfrom May 23, 2025
Merged
feat: added type aliases for reflect kinds to provide a single access point#49Akalanka47000 merged 2 commits intomainfrom
Akalanka47000 merged 2 commits intomainfrom
Conversation
Reviewer's GuideThis PR centralizes reflect.Kind usage by introducing alias variables in the elemental package and refactors existing code and tests to use these aliases (including a custom ObjectID type) instead of direct reflect.Kind references. Class Diagram: New 'elemental' Type Aliases and 'core.Field' UpdateclassDiagram
class elemental_TypeAliases {
<<Go Package: elemental>>
+Slice : reflect.Kind
+Map : reflect.Kind
+Struct : reflect.Kind
+Interface : reflect.Kind
+Array : reflect.Kind
+Bool : reflect.Kind
+Int : reflect.Kind
+Int32 : reflect.Kind
+Int64 : reflect.Kind
+Uint : reflect.Kind
+Uint8 : reflect.Kind
+Uint16 : reflect.Kind
+Uint32 : reflect.Kind
+Uint64 : reflect.Kind
+Float32 : reflect.Kind
+Float64 : reflect.Kind
+String : reflect.Kind
+ObjectID : reflect.Kind
}
class core_Field {
<<Go Struct: core.Field>>
+Type : reflect.Kind
+Schema : *Schema
+Required : bool
+Default : any
}
core_Field ..> elemental_TypeAliases : uses aliases for Type attribute
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @Akalanka47000 - I've reviewed your changes - here's some feedback:
- Relying on reflect.Kind for custom types like ObjectID can collide (e.g. primitive.ObjectID.Kind() == Array); consider updating Field.Type to accept reflect.Type directly for truly distinct types.
- The new alias file only covers a subset of reflect.Kinds—if you need pointer, function, channel, complex or unsafe types you should extend the list for completeness.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
core/schema_types.go
Outdated
|
|
||
| type Field struct { | ||
| Type reflect.Kind // Type of the field. Can be any of the reflect.Kind types | ||
| Type reflect.Kind // Type of the field. Can be any of the reflect.Kind types, or any of the aliases defined in the elemental package such as elemental.ObjectID or a custom reflected type |
There was a problem hiding this comment.
issue: Field.Type’s signature is inconsistent with custom reflect.Type support
Consider changing Field.Type to use reflect.Type or a union type to support both reflect.Kind and custom types, as implied by the updated comment.
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Provide centralized reflect.Kind aliases in the elemental package and migrate all schema Type definitions to use these new aliases instead of direct reflect.Kind references.
New Features:
schema_reflect_types.gofile that defines elemental aliases for common reflect.Kinds (e.g., Slice, Map, Struct, Interface, Array, Bool, numeric types, String) and a custom ObjectID alias.Enhancements:
reflect.*Kind usages in core schema definitions and tests with the correspondingelemental.*type aliases to unify type references.