feat: Generate one file per route client - #458
Merged
Merged
Conversation
The resource client classes were all serialized into src/SeamClient.php, producing a single ~9000 line file. Generate each client into its own file under src/Routes instead, leaving src/SeamClient.php with just the SeamClient class. Each route file imports only what its methods reference: the SeamClient, the resource classes it deserializes into, and, for ActionAttemptsClient, the errors thrown by poll_until_ready. Child clients share their parent's namespace, so they need no import. The client class bodies are byte identical to the ones previously emitted into src/SeamClient.php, and the classes are PSR-4 autoloaded by the existing Seam\ prefix mapping, so composer.json needs no change. The classes are now under Seam\Routes rather than Seam, matching the Seam\Resources convention. They remain reachable exactly as before through the SeamClient properties, e.g. $seam->acs->users. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MicfU2S3miuTWZtejb3w8w
razor-x
force-pushed
the
claude/php-codegen-split-routes-2rfwap
branch
from
July 29, 2026 00:58
ad715fa to
891c67e
Compare
razor-x
marked this pull request as ready for review
July 29, 2026 01:01
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
The resource client classes were all serialized into
src/SeamClient.php, producing a single 8950 line file. This generates each client into its own file undersrc/Routesinstead, leavingsrc/SeamClient.phpwith just theSeamClientclass at 155 lines.The 42 client class bodies are byte identical to the ones previously emitted into
src/SeamClient.php— this only changes where the generator writes them.Changes
Codegen
codegen/lib/layouts/route.ts(new) — builds the per-file context for one client class. Holds the method context builder moved out ofseam-client.ts, plusgetUseStatements, which derives each file's imports from what it actually references: theSeamClient, the resource classes its methods deserialize into, and, forActionAttemptsClientonly, the errors thrown bypoll_until_ready. Child clients share their parent's namespace, so they need no import.codegen/layouts/route.hbs(new) — namespace, imports, then the existingclient-classpartial unchanged.codegen/lib/layouts/seam-client.ts,codegen/layouts/seam-client.hbs— dropped the{{#each clients}}loop and the resource imports; now emitsuse Seam\Routes\...Client;for the 20 top-level clients only.codegen/lib/routes.ts— writessrc/Routes/{ClientName}Client.phpper client.codegen/smith.ts— cleans./src/Routesbefore each run.Other
.gitattributes— addedsrc/Routes/*.php, and alsosrc/SeamClient.php, which was generated but never marked.Namespace
The classes are now under
Seam\Routesrather thanSeam, matching theSeam\Resourcesconvention introduced in #454. That keeps them PSR-4 clean, so they are autoloaded by the existingSeam\prefix mapping andcomposer.jsonneeds no change.They remain reachable exactly as before through the
SeamClientproperties, which is how they are used:Verification
npm run typecheck,npm run lint, and the prettier check all pass.php -lon every file undersrc/reports no syntax errors.src/SeamClient.phpagainst the new files: zero differences.$seam->acs->users,$seam->thermostats->schedules) pluspoll_until_readywork.phpuniterrors onHttpErrorTest::testNonSeamError, but this is environmental rather than caused by this change — the sandbox proxy returnscURL error 56: CONNECT tunnel failed, response 403where the test expects a DNS resolution failure. The identical failure reproduces onmainwith these changes stashed.🤖 Generated with Claude Code
https://claude.ai/code/session_01MicfU2S3miuTWZtejb3w8w