Repository navigation
refactor(pivot): one function per file, and the three long functions in steps - #171
Merged
Merged
Conversation
PowerShellUniversal.Component.Pivot.psm1 held 66 functions, the module's settings and two C# sources in here-strings. It now only loads: - Public/: the 11 exported commands, one per file (exports follow the files) - Private/: the 55 helpers, one per file - Private/Settings/: the $Script: limits, patterns and state, by topic, loaded after the functions - Private/ReportWriter.cs and HttpTransport.cs: the C# the report engine compiles on first use; Get-UDPivotTypeSource gives each a per-content type name, which both here-strings computed by hand before Every function's text moved unchanged (split by the parser's extents). Build-Module copies Public/ and Private/ (.ps1 and .cs) into the built module and refuses a file named like one of shared/powershell. A source checkout loads shared/powershell directly, recognised by the missing SHARED.txt that the build writes into Private/. Four tests read the module's source text: they read the tip ids and import limits from Private/Settings and the help and error-mark lines from Public/ now; only their paths changed. A new build test checks that the built module carries every Public/ and Private/ file. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
New-UDPivotReport had 267 code lines. It now checks its parameters and puts the props together from helpers, each with one job and its inputs as parameters: the parameter checks, the server's rows or the reader's problem, the storage key, the props every report has, export, view, field and display props, the templates and their store (shipped views, store views, the merged list, its cap, the store's endpoints), the events and the admin panel. The order of the steps, their messages and the props stay as they were. 95 code lines remain, 55 of them parameters. PivotModule.Tests.ps1 checks that Public/ matches FunctionsToExport, that every $Bound['key'] a helper reads is a parameter of a public command, the admin panel's template count, and an empty -Id. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Invoke-UDPivotTemplateStore had 158 code lines and six script blocks that read its variables through scope. Each block is a helper now, with its inputs as parameters: the store context (scope, user key, folder, limit, request), the stored views and one custom-store entry, which views a report lists, the views of a name, a custom store's request, deleting one file, clearing stored copies, a free file name and writing a view. The steps keep their order and messages; ConvertTo-UDPivotViewFile and Get-UDPivotSchemaUrl are still called from the function itself, so they read its -Headers as before. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Invoke-UDPivotReport had 150 code lines. It now runs its steps through helpers with their inputs as parameters: the parameters of each engine, the REST engine's inputs, the output path and format, the view or layout and title, the REST render or link, and for the command line the data file, the arguments, the answer and the run in a private work folder. ShouldProcess, the order of the checks and the messages stay where they were. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The module file and the three long functions are within the limits now: Pivot.psm1 from 2,731 to 10 code lines, New-UDPivotReport from 267 to 95, Invoke-UDPivotTemplateStore from 158 to 51, Invoke-UDPivotReport from 150 to 55. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Get-UDPivotReportTemplate checks, registers the store's endpoints and returns props: Resolve-UDPivotReportTemplate says that better. - Build-Module refuses a name clash with shared/powershell only where the shared copy lands (Private/*.ps1, not Private/Settings or .cs files). - The build test imports the built folder in a process of its own and compares its exports with the manifest. - The -Bound test also reads $Bound.Keys -contains 'X' and says what it does not check. Refs #163 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Refs #163
PowerShellUniversal.Component.Pivot.psm1held 66 functions, the settings and two C# sources in here-strings. This pull request splits it into one function per file and shortens the three Pivot functions over 100 code lines. Commands, parameters, help and output stay the same.What changed
Public/: the 11 exported commands, one per file.Export-ModuleMembertakes the file names;FunctionsToExportin the manifest is unchanged.Private/: the helpers, one per file.Private/Settings/holds the$Script:limits, patterns and state by topic. They load after the functions, because the report engine's settings call one.Private/ReportWriter.csandPrivate/HttpTransport.cs: the C# the report engine compiles on first use.Get-UDPivotTypeSourcegives each a type name from its content hash. The two here-strings used to compute that separately..psm1only loads. A source checkout loadsshared/powershelldirectly. It is recognised by the missingPrivate/SHARED.txt, which the build writes. The old check (noPrivate/folder at all) no longer works once the module has its ownPrivate/.build/Build-Module.ps1copiesPublic/andPrivate/(.ps1and.cs) into the built module.New-UDPivotReport,Invoke-UDPivotTemplateStoreandInvoke-UDPivotReportrun their steps through helpers with one job each. Inputs are passed as parameters, and the six script blocks of the template store became functions. Each step keeps its order, side effects and messages. Calls that read$Headers,$User,$Rolesor$Queryof the caller still do so: through-Cmdlet $PSCmdlet, or from the same function as before.$PSBoundParametersas-Bound. Parameters with defaults (-Id,-Locale,-TimeZone,-Theme,-FileName,-MaxBytes,-TimeoutSec) are passed on their own, because they are not in$PSBoundParameters. A test checks that every$Bound['key']a helper reads is a parameter of a public command.Private/Settings/orPublic/; only their paths changed. New:PivotModule.Tests.ps1(Public/ matchesFunctionsToExport, the-Boundkeys, the admin panel's template count, an empty-Id) and a build test that the built module carries everyPublic/andPrivate/file and, imported in a process of its own, exports the manifest's commands.Build-Module.ps1refuses aPrivate/*.ps1named like one ofshared/powershell, which the build copies into the same folder.Commit by commit: the move with the test paths (every function's text unchanged, split by the parser's extents), then one commit per shortened function, the baseline, and a last commit with names and build checks. Pester passes on each commit.
Why the
.psm1dot-sources instead of a merged file in the buildPSU imports the module into each app runspace. Its docs set no file layout for a module; they show a
.psd1with a.psm1root module. The PSU plugin's module template (eizedev/claude-plugins#89) and AGENTS.md usePublic/andPrivate/dot-sourced at import. Dot-sourcing keeps the tested source and the shipped module the same, and error positions point to the real files.The cost, measured on macOS with PowerShell 7.6 (built module,
Endpointstub; not measured on PSU or Windows):I do not consider about 11 ms per runspace import material. If it turns out to matter on PSU, the build can merge the files into the shipped
.psm1without changing the source layout.Growth numbers
PowerShellUniversal.Component.Pivot.psm1(file)New-UDPivotReportInvoke-UDPivotTemplateStoreInvoke-UDPivotReportThe baseline is lowered in this pull request. No new offender. The largest Pivot helper now has 93 code lines (
ConvertTo-UDPivotFieldDefault, unchanged).Checks
Get-Command -Modulewith parameter sets, parameter attributes andOutputType,Get-Help -Fullof every command, and the exported functions: identical before and after. Checked for the source module and the built module.docs/site/Build-Site.ps1:docs/site/generated/is identical before and after. Its examples run the realNew-UDPivotReport.main: 357 and 7; five tests are new). All modules built. WithPIVOTKIT_TEST_CLI=1, the two tests against the installed pivotkit command line pass too.npm test: 165 passed. PSScriptAnalyzer as in CI: 0 findings. Growth: all four guards ok.Build-Module.ps1for all five modules. The built Pivot module carries the same files as before plusPublic/,Private/*.ps1,Private/Settings/andPrivate/*.cs.docs/(no page names the module file),docs/development, Build-Site, CI, and the tests that read source text.Not in this pull request
New-UDEChart(193 lines) and the ECharts module file: echarts: Public/Private files and a shorter New-UDEChart #169. They belong to another module with its own CHANGELOG.throwstrings, and whether the report engine becomes its own module.Get-UDPivotSqlColumnDescriptionis 54 code lines now, below the limit.shared/powershell/ConvertTo-PSUComponentData.ps1is shared by every module, so moving it is a change for all of them.🤖 Generated with Claude Code