Skip to content

Commit

Permalink
fix: make getRouteRulesForPath return readonly type
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 10, 2024
1 parent 8475dcf commit ce25779
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export interface CachedEventHandlerOptions<T = any>
shouldBypassCache?: (event: H3Event) => boolean | Promise<boolean>;
getKey?: (event: H3Event) => string | Promise<string>;
headersOnly?: boolean;
varies?: string[];
varies?: string[] | readonly string[];
}

function escapeKey(key: string | string[]) {
Expand Down
11 changes: 10 additions & 1 deletion src/runtime/route-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export function getRouteRules(event: H3Event): NitroRouteRules {
return event.context._nitro.routeRules;
}

export function getRouteRulesForPath(path: string): NitroRouteRules {
type DeepReadonly<T> =
T extends Record<string, any>
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
: T extends Array<infer U>
? ReadonlyArray<DeepReadonly<U>>
: T;

export function getRouteRulesForPath(
path: string
): DeepReadonly<NitroRouteRules> {
return defu({}, ..._routeRulesMatcher.matchAll(path).reverse());
}

0 comments on commit ce25779

Please sign in to comment.