Repository navigation
refactor: frontend takes types, enums, rules and URLs from the generated client - #329
Merged
Merged
Conversation
…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
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
|
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.



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:
moderatorrole, and the rate-limit modal can pickleaky_bucket.client.buildUrl, typed against the generated request, and a test pins the repeated parameters.EventSourceon 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,zUserUpdateandzSystemSettingsSchemaInputbefore 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.firstIssueinlib/validation.tswords 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 secondBrowsedEvent), andAuthState.userRoleis aUserRole, 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
includeInEntryand importing them from$lib/api/zod.genwould move them back into the lazy route chunks.Tests: the global
$lib/apimock now replaces only the SDK functions and keeps enums, schemas and the client real, since an automocked Zod schema returnsundefinedfromsafeParse. The three test files that override$lib/apiand the four that override$lib/formattersspreadimportOriginal()into their factories. The replay tests drive a mocked generated stream instead of a fakeEventSource.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 openapiplusnpm 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
moderatorrole, and the rate-limit modal can pickleaky_bucket.client.buildUrlwith the parameter repeated as the API expects.EventSource.Validation and defaults
firstIssueinlib/validation.tswording the first Zod issue as a sentence like "Password must be at least 8 characters".AuthState.userRoleis nowUserRole.Written for commit 21495f8. Summary will update on new commits.