feat(compiler): support consumer-owned route metadata - #1
Draft
yoshinoriishii wants to merge 6 commits into
Draft
yoshinoriishii wants to merge 6 commits into
yoshinoriishii wants to merge 6 commits into
Conversation
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.
Internal review for an intended upstream contribution. This PR has now been submitted as unjs/fetchdts#195.
What this changes
The compiler already emits supplied
*Typemetadata fields generically, but the publicRoute.metadatatype accepts only fields owned by fetchdts. This adds an emptyRouteMetadataExtensionregistry that compiler integrations can augment:cachePolicyType: '{ maxAge: 60 }'is then accepted and emitted ascachePolicy: { maxAge: 60 }. Unknown fields remain type errors, and fetchdts does not interpret the added field.This aligns the public type with the compiler's generic metadata behavior and avoids casts or a parallel route schema when an integration needs to carry its own typed metadata through the same route tree.
Why module augmentation
It adds no runtime behavior or generic parameters to
Route,RouteSet, andcompileRoutes, and distinct integrations can register fields together. It also follows an established Nuxt/UnJS pattern; the closest precedent is H3's intentionally emptyRouteRulesinterface.Module augmentation applies project-wide. If that scope is undesirable, an explicit generic could be considered instead.
Consumers can access the emitted field through the existing
TypedFetchResolvedMetatype.Tests
The focused test covers a registered field, rejection of an unknown field, concrete emitted output, and coexistence with built-in metadata.
Local checks passed:
pnpm lint,pnpm test:knip,pnpm test:versions,pnpm build,pnpm test:types, andpnpm test:unit -- --coverage(183 passed, one existing todo, no type errors).