-
Notifications
You must be signed in to change notification settings - Fork 29
feat: add support for averages output generation #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…s writer to separate class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive support for generating average aggregates on Eloquent relationships in TypeScript model definitions. The implementation mirrors the existing sums functionality and provides flexible configuration options for controlling how averages are included in the generated output.
Key changes:
- Introduced
WriteAvgaction for generating average aggregate TypeScript definitions - Added CLI options
--no-averagesand--optional-averagesfor controlling average inclusion and optionality - Extended all relevant generator classes to handle averages alongside existing sums, counts, and exists functionality
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Tests/Feature/Actions/WriteAvgTest.php | Comprehensive test suite for the new WriteAvg action covering various output formats and case styles |
| src/Actions/WriteAvg.php | Core action class that generates TypeScript definitions for average aggregates |
| src/Commands/ModelTyperCommand.php | Added CLI options for controlling averages generation |
| src/Actions/Generator.php | Extended main generator to accept and pass through averages parameters |
| src/Actions/GenerateJsonOutput.php | Added averages support to JSON output generation |
| src/Actions/GenerateCliOutput.php | Added averages support to CLI/TypeScript output generation |
| src/Actions/BuildModelDetails.php | Extended model builder to extract averages from Laravel models |
| config/modeltyper.php | Added configuration options for averages functionality |
| readme.md | Updated documentation to include averages feature usage examples |
| $sums = collect($laravelModel->sums ?? [])->map(fn ($relation, $column) => [ | ||
| 'relation' => $relation, | ||
| 'column' => $column, | ||
| ])->values(); | ||
|
|
||
| $averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [ |
Copilot
AI
Jul 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter order in the map callback is incorrect. It should be fn ($column, $relation) to match the documented format 'column_to_sum' => 'relationship_name', or the documentation should be updated to match this implementation.
| $sums = collect($laravelModel->sums ?? [])->map(fn ($relation, $column) => [ | |
| 'relation' => $relation, | |
| 'column' => $column, | |
| ])->values(); | |
| $averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [ | |
| $sums = collect($laravelModel->sums ?? [])->map(fn ($column, $relation) => [ | |
| 'relation' => $relation, | |
| 'column' => $column, | |
| ])->values(); | |
| $averages = collect($laravelModel->averages ?? [])->map(fn ($column, $relation) => [ |
| 'column' => $column, | ||
| ])->values(); | ||
|
|
||
| $averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [ |
Copilot
AI
Jul 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter order in the map callback is incorrect. It should be fn ($column, $relation) to match the documented format 'column_to_average' => 'relationship_name'.
| $averages = collect($laravelModel->averages ?? [])->map(fn ($relation, $column) => [ | |
| $averages = collect($laravelModel->averages ?? [])->map(fn ($column, $relation) => [ |
| ]; | ||
| ``` |
Copilot
AI
Jul 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This closing bracket appears to be orphaned and doesn't match any opening bracket in the averages section, creating invalid PHP syntax in the documentation example.
| ]; | |
| ``` |
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This pull request introduces support for generating average aggregates for Eloquent relationships in the output, along with a new
WriteAvgaction and comprehensive tests.Key changes:
no-averagesandoptional-averagesto control inclusion and optionality of averages.WriteAvgaction for outputting averages.WriteAvgaction, covering:This enhancement provides more flexibility and completeness in model type generation, especially for projects that require average aggregates on relationships.