Repository navigation
fix: stop emitting the unused old field on registry tokens - #120
Open
simulieren wants to merge 1 commit into
Open
simulieren wants to merge 1 commit into
simulieren wants to merge 1 commit into
Conversation
Every token in the generated `.adonisjs/client/registry/index.ts` carried `old`, the whole route pattern repeated once per token, while the client URL builder (`createURL`) only reads `type`, `val` and `end`. On an app with ~1100 routes the tokens were two thirds of the generated file (466 kB of 681 kB) and `old` alone was 262 kB. The generator now keeps `type`, `val` and `end`. `AdonisEndpoint.tokens` is typed with a new `ClientRouteToken` where `old` is optional, so a registry generated by an earlier version still type-checks until it is regenerated, and the client passes its tokens to the http-server URL builder with an explicit assertion since that builder's type still declares `old`. Tests: the generator spec asserts the emitted token JSON, and a client spec builds a URL and issues a request from a registry whose tokens have no `old`.
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 #119.
What changes
RegistryGenerator#sanitizeTokenskeepstype,valandendonly.oldwas matchit's copy of the whole route pattern, repeated once per token, and nothing on the client reads it:createURLusestype/val/end,TuyauRoutermatches onpattern.AdonisEndpoint.tokensis typed with a new exportedClientRouteToken, which isClientRouteMatchItTokenswitholdoptional.Tuyau#createUrlBuilderbuilds theClientRouteJSON[]it hands to the http-server URL builder explicitly and asserts the token type, since that builder's type still declaresold.@tuyau/core.Backward compatibility
old) still type-checks against the newAdonisEndpointand still works at runtime, becauseoldis optional and ignored.createURLnever touchedold.token.oldoffregistry.routes[...].tokens, which now seesstring | undefined.Measured
On an AdonisJS app with 1142 named routes,
.adonisjs/client/registry/index.ts:Verification
packages/core: 131 tests pass (one added),tsc --noEmitclean,oxlintclean,pnpm buildfor all packages followed bypnpm typecheckfor the whole workspace is clean.generate_registry.spec.tsasserts the emitted token JSON contains no"old".client.spec.tsadds a case that builds/users/42withurlForand issues a request throughtuyau.apifrom a registry whose tokens carry noold. The existing fixtures keepold, so the old shape is still exercised too.