Skip to content

feat: added type aliases for reflect kinds to provide a single access point#49

Merged
Akalanka47000 merged 2 commits intomainfrom
feature/schema-type-aliases
May 23, 2025
Merged

feat: added type aliases for reflect kinds to provide a single access point#49
Akalanka47000 merged 2 commits intomainfrom
feature/schema-type-aliases

Conversation

@Akalanka47000
Copy link
Copy Markdown
Member

@Akalanka47000 Akalanka47000 commented May 22, 2025

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:

  • Introduce a new schema_reflect_types.go file 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:

  • Replace all direct reflect.* Kind usages in core schema definitions and tests with the corresponding elemental.* type aliases to unify type references.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented May 22, 2025

Reviewer's Guide

This 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' Update

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Add type alias variables for reflect kinds in elemental package
  • Create schema_reflect_types.go with built-in type alias declarations
  • Define ObjectID alias using primitive.NilObjectID.Kind()
core/schema_reflect_types.go
Extend Field.Type documentation to include elemental aliases
  • Update the Type field comment in schema_types.go to reference elemental aliases and custom reflected types
core/schema_types.go
Refactor code and tests to use elemental type aliases instead of reflect.Kind
  • Replace reflect.X with elemental.X in schemas across fixtures and tests
  • Update object reference fields to use the new elemental.ObjectID alias
tests/fixtures/fixtures.go
tests/core_schema_test.go
tests/core_audit_test.go
tests/core_middleware_test.go
tests/core_triggers_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]
sourcery-ai bot previously approved these changes May 22, 2025
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown

codecov bot commented May 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@Akalanka47000 Akalanka47000 merged commit aba7c0d into main May 23, 2025
6 checks passed
@Akalanka47000 Akalanka47000 deleted the feature/schema-type-aliases branch May 23, 2025 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant