Skip to content

refactor: frontend takes types, enums, rules and URLs from the generated client - #329

Merged
HardMax71 merged 1 commit into
mainfrom
refactor/frontend-generated-enums-zod
Oct 11, 2026
Merged

HardMax71 merged 1 commit into
mainfrom
refactor/frontend-generated-enums-zod

Conversation

@HardMax71

@HardMax71 HardMax71 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Closes #324, step 1 of #328.

The frontend now takes everything that comes from the backend out of the hey-api output instead of hand-written copies. The generator emits runtime enums (enums: 'javascript') and a Zod schema per model, and the index re-exports the client and the schemas, so it's all one import from $lib/api.

The copies had drifted, so this fixes real bugs:

  • The admin user form can pick the moderator role, and the rate-limit modal can pick leaky_bucket.
  • The event filter offers all 57 event types instead of a hand-picked 10.
  • Exporting events with an event-type filter returned 422. The URL was built by hand and joined the types with commas, while the API wants the parameter repeated. It's now built by client.buildUrl, typed against the generated request, and a test pins the repeated parameters.
  • The replay status stream uses the generated SSE function, with typed events and the client's retry, instead of a raw EventSource on a hand-built URL.

Rules and defaults come from the generated schemas too. Register, the admin user form and the admin system settings validate with zUserCreate, zUserUpdate and zSystemSettingsSchemaInput before calling the API, the settings inputs take their min and max from the schema, and the Settings form and new rate-limit rules start from the API's own defaults. firstIssue in lib/validation.ts words the first Zod issue as a sentence such as "Password must be at least 8 characters".

The duplicate types are gone (ThemeValue, UserForm, ReplayPreview, the second BrowsedEvent), and AuthState.userRole is a UserRole, so every role comparison is type-checked now.

Re-exporting the Zod schemas from the index puts Zod and all ~300 schemas in the main chunk: it grows from 30 KB to 63 KB gzipped. Generating the schemas without includeInEntry and importing them from $lib/api/zod.gen would move them back into the lazy route chunks.

Tests: the global $lib/api mock now replaces only the SDK functions and keeps enums, schemas and the client real, since an automocked Zod schema returns undefined from safeParse. The three test files that override $lib/api and the four that override $lib/formatters spread importOriginal() into their factories. The replay tests drive a mocked generated stream instead of a fake EventSource.

The TanStack Query and date transformer plugins wait for #326, as planned in the issue.

Checked: npm run check, lint, Stylelint, Prettier, 1150 Vitest tests with coverage above the thresholds, the production build, mkdocs build --strict, and ./deploy.sh openapi plus npm run generate:api, which leave no diff.


Summary by cubic

The frontend now takes everything that comes from the backend—types, enums, validation rules, defaults, URLs, and SSE streams—from the hey-api generated client instead of hand-written copies, which had drifted. Re-exporting the Zod schemas from the index grows the main chunk from 30 KB to 63 KB gzipped.

Bug Fixes

  • The admin user form can pick the moderator role, and the rate-limit modal can pick leaky_bucket.
  • The event filter offers all 57 event types instead of a hand-picked 10.
  • Exporting events with an event-type filter no longer returns 422; the URL is built by client.buildUrl with the parameter repeated as the API expects.
  • The replay status stream uses the generated SSE function with typed events instead of a raw EventSource.

Validation and defaults

  • Register, the admin user form, and admin system settings validate against the generated schemas, with firstIssue in lib/validation.ts wording the first Zod issue as a sentence like "Password must be at least 8 characters".
  • Settings inputs take their min and max from the schema, and the Settings form and new rate-limit rules start from the API's defaults.
  • Duplicate types are gone, and AuthState.userRole is now UserRole.

Written for commit 21495f8. Summary will update on new commits.

View guided diff Turn on auto-fix

…ted client

hey-api now emits runtime enums and Zod schemas, and the index re-exports
the client and the schemas. Option lists, validation, defaults, field
bounds, the replay status stream and the export URL come from that output
instead of hand-written copies, which had drifted: the moderator role and
leaky_bucket were missing, the event filter offered 10 of 57 types, and an
export with an event-type filter got a 422 from the comma-joined parameter.

Closes #324
@HardMax71 HardMax71 added the area: frontend Svelte UI and the generated API client label Oct 11, 2026
@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 117dfd6b-ebd4-4301-bc1c-820280cb2d40

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

@codecov-commenter

codecov-commenter commented Oct 11, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 75.00000% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rontend/src/lib/admin/stores/eventsStore.svelte.ts 70.83% 1 Missing and 6 partials ⚠️
frontend/src/routes/admin/AdminSettings.svelte 68.42% 2 Missing and 4 partials ⚠️
frontend/src/lib/validation.ts 66.66% 0 Missing and 3 partials ⚠️
frontend/src/routes/admin/AdminUsers.svelte 78.57% 2 Missing and 1 partial ⚠️
.../src/components/admin/users/RateLimitsModal.svelte 50.00% 0 Missing and 1 partial ⚠️
...tend/src/components/admin/users/UserFilters.svelte 50.00% 0 Missing and 1 partial ⚠️
...nd/src/components/admin/users/UserFormModal.svelte 66.66% 0 Missing and 1 partial ⚠️
frontend/src/routes/admin/AdminExecutions.svelte 75.00% 0 Missing and 1 partial ⚠️
frontend/src/stores/theme.svelte.ts 87.50% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Flag Coverage Δ
backend-e2e 82.89% <ø> (+0.03%) ⬆️
backend-unit 72.37% <ø> (ø)
frontend-unit 86.11% <75.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...end/src/components/admin/events/EventsTable.svelte 76.84% <ø> (ø)
.../components/admin/events/ReplayPreviewModal.svelte 90.00% <ø> (ø)
frontend/src/lib/admin/events/eventTypes.ts 100.00% <100.00%> (ø)
frontend/src/lib/admin/rate-limits/rateLimits.ts 100.00% <100.00%> (ø)
frontend/src/lib/api-interceptors.ts 95.83% <ø> (ø)
frontend/src/lib/formatters.ts 96.22% <100.00%> (+0.14%) ⬆️
frontend/src/routes/Register.svelte 100.00% <100.00%> (ø)
frontend/src/routes/Settings.svelte 85.40% <100.00%> (+0.07%) ⬆️
frontend/src/stores/auth.svelte.ts 91.73% <100.00%> (ø)
.../src/components/admin/users/RateLimitsModal.svelte 76.57% <50.00%> (-1.11%) ⬇️
... and 8 more

... and 2 files with indirect coverage changes

Components Coverage Δ
Backend 91.38% <ø> (+0.03%) ⬆️
Frontend 86.11% <75.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HardMax71
HardMax71 merged commit 3f790ad into main Oct 11, 2026
22 checks passed
@HardMax71
HardMax71 deleted the refactor/frontend-generated-enums-zod branch October 11, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: frontend Svelte UI and the generated API client documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: frontend uses generated enums and Zod schemas, no hand copies of the API

2 participants