Skip to content

feat: Generate one file per route client - #458

Merged
razor-x merged 1 commit into
mainfrom
claude/php-codegen-split-routes-2rfwap
Jul 29, 2026
Merged

feat: Generate one file per route client#458
razor-x merged 1 commit into
mainfrom
claude/php-codegen-split-routes-2rfwap

Conversation

@razor-x

@razor-x razor-x commented Jul 29, 2026

Copy link
Copy Markdown
Member

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 under src/Routes instead, leaving src/SeamClient.php with just the SeamClient class 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 of seam-client.ts, plus getUseStatements, which derives each file's imports from what it actually references: the SeamClient, the resource classes its methods deserialize into, and, for ActionAttemptsClient only, the errors thrown by poll_until_ready. Child clients share their parent's namespace, so they need no import.
  • codegen/layouts/route.hbs (new) — namespace, imports, then the existing client-class partial unchanged.
  • codegen/lib/layouts/seam-client.ts, codegen/layouts/seam-client.hbs — dropped the {{#each clients}} loop and the resource imports; now emits use Seam\Routes\...Client; for the 20 top-level clients only.
  • codegen/lib/routes.ts — writes src/Routes/{ClientName}Client.php per client.
  • codegen/smith.ts — cleans ./src/Routes before each run.

Other

  • .gitattributes — added src/Routes/*.php, and also src/SeamClient.php, which was generated but never marked.

Namespace

The classes are now under Seam\Routes rather than Seam, matching the Seam\Resources convention introduced in #454. That keeps them PSR-4 clean, so they are autoloaded by the existing Seam\ prefix mapping and composer.json needs no change.

They remain reachable exactly as before through the SeamClient properties, which is how they are used:

$seam = new Seam\SeamClient("YOUR_API_KEY");
$seam->acs->users->list();

Verification

  • npm run typecheck, npm run lint, and the prettier check all pass.
  • php -l on every file under src/ reports no syntax errors.
  • Diffed all 42 client class blocks extracted from the previous src/SeamClient.php against the new files: zero differences.
  • Reflection pass over all 42 classes: each autoloads from its expected file, every parameter, return, and property type resolves, and nested wiring ($seam->acs->users, $seam->thermostats->schedules) plus poll_until_ready work.
  • phpunit errors on HttpErrorTest::testNonSeamError, but this is environmental rather than caused by this change — the sandbox proxy returns cURL error 56: CONNECT tunnel failed, response 403 where the test expects a DNS resolution failure. The identical failure reproduces on main with these changes stashed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MicfU2S3miuTWZtejb3w8w

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
razor-x force-pushed the claude/php-codegen-split-routes-2rfwap branch from ad715fa to 891c67e Compare July 29, 2026 00:58
@razor-x razor-x changed the title Refactor SDK to split SeamClient into separate route clients refactor(codegen): Generate one file per route client Jul 29, 2026
@razor-x
razor-x marked this pull request as ready for review July 29, 2026 01:01
@razor-x razor-x changed the title refactor(codegen): Generate one file per route client feat: Generate one file per route client Jul 29, 2026
@razor-x
razor-x merged commit 254e4ac into main Jul 29, 2026
5 checks passed
@razor-x
razor-x deleted the claude/php-codegen-split-routes-2rfwap branch July 29, 2026 01:02
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.

2 participants