Skip to content

feat(compiler): support consumer-owned route metadata - #1

Draft
yoshinoriishii wants to merge 6 commits into
mainfrom
proposal/extensible-route-metadata
Draft

yoshinoriishii wants to merge 6 commits into
mainfrom
proposal/extensible-route-metadata

Conversation

@yoshinoriishii

@yoshinoriishii yoshinoriishii commented Sep 6, 2026

Copy link
Copy Markdown

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 *Type metadata fields generically, but the public Route.metadata type accepts only fields owned by fetchdts. This adds an empty RouteMetadataExtension registry that compiler integrations can augment:

declare module 'fetchdts/compiler' {
  interface RouteMetadataExtension {
    cachePolicy: unknown
  }
}

cachePolicyType: '{ maxAge: 60 }' is then accepted and emitted as cachePolicy: { 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, and compileRoutes, and distinct integrations can register fields together. It also follows an established Nuxt/UnJS pattern; the closest precedent is H3's intentionally empty RouteRules interface.

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 TypedFetchResolvedMeta type.

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, and pnpm test:unit -- --coverage (183 passed, one existing todo, no type errors).

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.

1 participant