@rangojs/router 0.0.0-experimental.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +43 -0
- package/README.md +19 -0
- package/dist/bin/rango.js +227 -0
- package/dist/vite/index.js +3039 -0
- package/package.json +171 -0
- package/skills/caching/SKILL.md +191 -0
- package/skills/debug-manifest/SKILL.md +108 -0
- package/skills/document-cache/SKILL.md +180 -0
- package/skills/fonts/SKILL.md +165 -0
- package/skills/hooks/SKILL.md +442 -0
- package/skills/intercept/SKILL.md +190 -0
- package/skills/layout/SKILL.md +213 -0
- package/skills/links/SKILL.md +180 -0
- package/skills/loader/SKILL.md +246 -0
- package/skills/middleware/SKILL.md +202 -0
- package/skills/mime-routes/SKILL.md +124 -0
- package/skills/parallel/SKILL.md +228 -0
- package/skills/prerender/SKILL.md +283 -0
- package/skills/rango/SKILL.md +54 -0
- package/skills/response-routes/SKILL.md +358 -0
- package/skills/route/SKILL.md +173 -0
- package/skills/router-setup/SKILL.md +346 -0
- package/skills/tailwind/SKILL.md +129 -0
- package/skills/theme/SKILL.md +78 -0
- package/skills/typesafety/SKILL.md +394 -0
- package/src/__internal.ts +175 -0
- package/src/bin/rango.ts +24 -0
- package/src/browser/event-controller.ts +876 -0
- package/src/browser/index.ts +18 -0
- package/src/browser/link-interceptor.ts +121 -0
- package/src/browser/lru-cache.ts +69 -0
- package/src/browser/merge-segment-loaders.ts +126 -0
- package/src/browser/navigation-bridge.ts +913 -0
- package/src/browser/navigation-client.ts +165 -0
- package/src/browser/navigation-store.ts +823 -0
- package/src/browser/partial-update.ts +600 -0
- package/src/browser/react/Link.tsx +248 -0
- package/src/browser/react/NavigationProvider.tsx +346 -0
- package/src/browser/react/ScrollRestoration.tsx +94 -0
- package/src/browser/react/context.ts +53 -0
- package/src/browser/react/index.ts +52 -0
- package/src/browser/react/location-state-shared.ts +120 -0
- package/src/browser/react/location-state.ts +62 -0
- package/src/browser/react/mount-context.ts +32 -0
- package/src/browser/react/use-action.ts +240 -0
- package/src/browser/react/use-client-cache.ts +56 -0
- package/src/browser/react/use-handle.ts +203 -0
- package/src/browser/react/use-href.tsx +40 -0
- package/src/browser/react/use-link-status.ts +134 -0
- package/src/browser/react/use-mount.ts +31 -0
- package/src/browser/react/use-navigation.ts +140 -0
- package/src/browser/react/use-segments.ts +188 -0
- package/src/browser/request-controller.ts +164 -0
- package/src/browser/rsc-router.tsx +352 -0
- package/src/browser/scroll-restoration.ts +324 -0
- package/src/browser/segment-structure-assert.ts +67 -0
- package/src/browser/server-action-bridge.ts +762 -0
- package/src/browser/shallow.ts +35 -0
- package/src/browser/types.ts +478 -0
- package/src/build/generate-manifest.ts +377 -0
- package/src/build/generate-route-types.ts +828 -0
- package/src/build/index.ts +36 -0
- package/src/build/route-trie.ts +239 -0
- package/src/cache/cache-scope.ts +563 -0
- package/src/cache/cf/cf-cache-store.ts +428 -0
- package/src/cache/cf/index.ts +19 -0
- package/src/cache/document-cache.ts +340 -0
- package/src/cache/index.ts +58 -0
- package/src/cache/memory-segment-store.ts +150 -0
- package/src/cache/memory-store.ts +253 -0
- package/src/cache/types.ts +392 -0
- package/src/client.rsc.tsx +83 -0
- package/src/client.tsx +643 -0
- package/src/component-utils.ts +76 -0
- package/src/components/DefaultDocument.tsx +23 -0
- package/src/debug.ts +233 -0
- package/src/default-error-boundary.tsx +88 -0
- package/src/deps/browser.ts +8 -0
- package/src/deps/html-stream-client.ts +2 -0
- package/src/deps/html-stream-server.ts +2 -0
- package/src/deps/rsc.ts +10 -0
- package/src/deps/ssr.ts +2 -0
- package/src/errors.ts +295 -0
- package/src/handle.ts +130 -0
- package/src/handles/MetaTags.tsx +193 -0
- package/src/handles/index.ts +6 -0
- package/src/handles/meta.ts +247 -0
- package/src/host/cookie-handler.ts +159 -0
- package/src/host/errors.ts +97 -0
- package/src/host/index.ts +56 -0
- package/src/host/pattern-matcher.ts +214 -0
- package/src/host/router.ts +330 -0
- package/src/host/testing.ts +79 -0
- package/src/host/types.ts +138 -0
- package/src/host/utils.ts +25 -0
- package/src/href-client.ts +202 -0
- package/src/href-context.ts +33 -0
- package/src/index.rsc.ts +121 -0
- package/src/index.ts +165 -0
- package/src/loader.rsc.ts +207 -0
- package/src/loader.ts +47 -0
- package/src/network-error-thrower.tsx +21 -0
- package/src/outlet-context.ts +15 -0
- package/src/prerender/param-hash.ts +35 -0
- package/src/prerender/store.ts +40 -0
- package/src/prerender.ts +156 -0
- package/src/reverse.ts +267 -0
- package/src/root-error-boundary.tsx +277 -0
- package/src/route-content-wrapper.tsx +193 -0
- package/src/route-definition.ts +1431 -0
- package/src/route-map-builder.ts +242 -0
- package/src/route-types.ts +220 -0
- package/src/router/error-handling.ts +287 -0
- package/src/router/handler-context.ts +158 -0
- package/src/router/intercept-resolution.ts +387 -0
- package/src/router/loader-resolution.ts +327 -0
- package/src/router/manifest.ts +216 -0
- package/src/router/match-api.ts +621 -0
- package/src/router/match-context.ts +264 -0
- package/src/router/match-middleware/background-revalidation.ts +236 -0
- package/src/router/match-middleware/cache-lookup.ts +382 -0
- package/src/router/match-middleware/cache-store.ts +276 -0
- package/src/router/match-middleware/index.ts +81 -0
- package/src/router/match-middleware/intercept-resolution.ts +281 -0
- package/src/router/match-middleware/segment-resolution.ts +184 -0
- package/src/router/match-pipelines.ts +214 -0
- package/src/router/match-result.ts +213 -0
- package/src/router/metrics.ts +62 -0
- package/src/router/middleware.ts +791 -0
- package/src/router/pattern-matching.ts +407 -0
- package/src/router/revalidation.ts +190 -0
- package/src/router/router-context.ts +301 -0
- package/src/router/segment-resolution.ts +1315 -0
- package/src/router/trie-matching.ts +172 -0
- package/src/router/types.ts +163 -0
- package/src/router.gen.ts +6 -0
- package/src/router.ts +2423 -0
- package/src/rsc/handler.ts +1443 -0
- package/src/rsc/helpers.ts +64 -0
- package/src/rsc/index.ts +56 -0
- package/src/rsc/nonce.ts +18 -0
- package/src/rsc/types.ts +236 -0
- package/src/segment-system.tsx +442 -0
- package/src/server/context.ts +466 -0
- package/src/server/handle-store.ts +229 -0
- package/src/server/loader-registry.ts +174 -0
- package/src/server/request-context.ts +554 -0
- package/src/server/root-layout.tsx +10 -0
- package/src/server/tsconfig.json +14 -0
- package/src/server.ts +171 -0
- package/src/ssr/index.tsx +296 -0
- package/src/theme/ThemeProvider.tsx +291 -0
- package/src/theme/ThemeScript.tsx +61 -0
- package/src/theme/constants.ts +59 -0
- package/src/theme/index.ts +58 -0
- package/src/theme/theme-context.ts +70 -0
- package/src/theme/theme-script.ts +152 -0
- package/src/theme/types.ts +182 -0
- package/src/theme/use-theme.ts +44 -0
- package/src/types.ts +1757 -0
- package/src/urls.gen.ts +8 -0
- package/src/urls.ts +1282 -0
- package/src/use-loader.tsx +346 -0
- package/src/vite/expose-action-id.ts +344 -0
- package/src/vite/expose-handle-id.ts +209 -0
- package/src/vite/expose-loader-id.ts +426 -0
- package/src/vite/expose-location-state-id.ts +177 -0
- package/src/vite/expose-prerender-handler-id.ts +429 -0
- package/src/vite/index.ts +2068 -0
- package/src/vite/package-resolution.ts +125 -0
- package/src/vite/version.d.ts +12 -0
- package/src/vite/virtual-entries.ts +114 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-safe route map builder
|
|
3
|
+
*
|
|
4
|
+
* Provides a fluent API for building route maps with prefixes.
|
|
5
|
+
* Can be imported in client code without pulling in server dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createRouteMap, registerRouteMap } from "rsc-router/browser";
|
|
10
|
+
*
|
|
11
|
+
* const routeMap = createRouteMap()
|
|
12
|
+
* .add(homeRoutes)
|
|
13
|
+
* .add(blogRoutes, "blog")
|
|
14
|
+
* .add(shopRoutes, "shop");
|
|
15
|
+
*
|
|
16
|
+
* registerRouteMap(routeMap.routes);
|
|
17
|
+
*
|
|
18
|
+
* declare global {
|
|
19
|
+
* namespace RSCRouter {
|
|
20
|
+
* interface RegisteredRoutes extends typeof routeMap.routes {}
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { PrefixRoutePatterns } from "./reverse.js";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Route map builder interface
|
|
30
|
+
*
|
|
31
|
+
* Accumulates route types through the builder chain for type-safe reverse.
|
|
32
|
+
*/
|
|
33
|
+
export interface RouteMapBuilder<TRoutes extends Record<string, string> = {}> {
|
|
34
|
+
/**
|
|
35
|
+
* Add routes without prefix
|
|
36
|
+
*/
|
|
37
|
+
add<T extends Record<string, string>>(routes: T): RouteMapBuilder<TRoutes & T>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Add routes with prefix (only URL patterns are prefixed, keys stay unchanged)
|
|
41
|
+
* @param routes - Route definitions to add
|
|
42
|
+
* @param prefix - URL prefix WITHOUT leading slash (e.g., "blog" not "/blog")
|
|
43
|
+
*/
|
|
44
|
+
add<T extends Record<string, string>, P extends string>(
|
|
45
|
+
routes: T,
|
|
46
|
+
prefix: P
|
|
47
|
+
): RouteMapBuilder<TRoutes & PrefixRoutePatterns<T, `/${P}`>>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The accumulated route map (for typeof extraction in module augmentation)
|
|
51
|
+
*/
|
|
52
|
+
readonly routes: TRoutes;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Add routes to a map with optional prefix
|
|
57
|
+
* Keys stay unchanged for composability - only URL patterns get prefixed.
|
|
58
|
+
*
|
|
59
|
+
* @param routeMap - The map to add routes to
|
|
60
|
+
* @param routes - Routes to add
|
|
61
|
+
* @param prefix - Optional prefix for URL paths WITHOUT leading slash (keys stay unchanged)
|
|
62
|
+
*/
|
|
63
|
+
function addRoutes(
|
|
64
|
+
routeMap: Record<string, string>,
|
|
65
|
+
routes: Record<string, string>,
|
|
66
|
+
prefix: string = ""
|
|
67
|
+
): void {
|
|
68
|
+
// Normalize prefix: remove leading slash if accidentally provided
|
|
69
|
+
const normalizedPrefix = prefix.startsWith("/") ? prefix.slice(1) : prefix;
|
|
70
|
+
|
|
71
|
+
for (const [key, pattern] of Object.entries(routes)) {
|
|
72
|
+
const prefixedPattern =
|
|
73
|
+
normalizedPrefix && pattern !== "/"
|
|
74
|
+
? `/${normalizedPrefix}${pattern}`
|
|
75
|
+
: normalizedPrefix && pattern === "/"
|
|
76
|
+
? `/${normalizedPrefix}`
|
|
77
|
+
: pattern;
|
|
78
|
+
// Use original key - enables reusable route modules
|
|
79
|
+
routeMap[key] = prefixedPattern;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Create a new route map builder
|
|
85
|
+
*
|
|
86
|
+
* @returns A builder for accumulating routes with type-safe prefixes
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const routeMap = createRouteMap()
|
|
91
|
+
* .add(homeRoutes)
|
|
92
|
+
* .add(blogRoutes, "blog");
|
|
93
|
+
*
|
|
94
|
+
* // Types are accumulated through the chain
|
|
95
|
+
* type AppRoutes = typeof routeMap.routes;
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function createRouteMap(): RouteMapBuilder<{}> {
|
|
99
|
+
const routeMap: Record<string, string> = {};
|
|
100
|
+
|
|
101
|
+
const builder: RouteMapBuilder<any> = {
|
|
102
|
+
add(routes: Record<string, string>, prefix?: string) {
|
|
103
|
+
addRoutes(routeMap, routes, prefix);
|
|
104
|
+
return builder;
|
|
105
|
+
},
|
|
106
|
+
get routes() {
|
|
107
|
+
return routeMap;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return builder;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Singleton route map instance - populated incrementally as routes are encountered
|
|
115
|
+
let globalRouteMap: Record<string, string> = {};
|
|
116
|
+
|
|
117
|
+
// Cached complete manifest - includes all routes (including lazy includes)
|
|
118
|
+
// Set from runtime cache or build-time import
|
|
119
|
+
let cachedManifest: Record<string, string> | null = null;
|
|
120
|
+
|
|
121
|
+
// Pre-computed route entries from build-time prefix tree leaf nodes.
|
|
122
|
+
// Used by evaluateLazyEntry() to skip running the handler for route matching.
|
|
123
|
+
let cachedPrecomputedEntries: Array<{
|
|
124
|
+
staticPrefix: string;
|
|
125
|
+
routes: Record<string, string>;
|
|
126
|
+
}> | null = null;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Register the route map globally for reverse to use at runtime
|
|
130
|
+
*
|
|
131
|
+
* Call this after building your route map to make it available to reverse.
|
|
132
|
+
* Routes are merged with any existing registered routes.
|
|
133
|
+
*
|
|
134
|
+
* @param map - The route map to register
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const routeMap = createRouteMap()
|
|
139
|
+
* .add(homeRoutes)
|
|
140
|
+
* .add(blogRoutes, "blog");
|
|
141
|
+
*
|
|
142
|
+
* registerRouteMap(routeMap.routes);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function registerRouteMap(map: Record<string, string>): void {
|
|
146
|
+
// Always merge with existing map (don't replace)
|
|
147
|
+
globalRouteMap = { ...globalRouteMap, ...map };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the globally registered route map
|
|
152
|
+
*
|
|
153
|
+
* Used internally by reverse to resolve route names to URLs at runtime.
|
|
154
|
+
* Returns the cached manifest if available (complete with lazy includes),
|
|
155
|
+
* otherwise returns the runtime-accumulated route map.
|
|
156
|
+
*
|
|
157
|
+
* @returns The registered route map
|
|
158
|
+
*/
|
|
159
|
+
export function getGlobalRouteMap(): Record<string, string> {
|
|
160
|
+
// Cached manifest is complete (includes lazy routes), so prefer it
|
|
161
|
+
if (cachedManifest) {
|
|
162
|
+
return cachedManifest;
|
|
163
|
+
}
|
|
164
|
+
return globalRouteMap;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Set the cached manifest (for runtime cache integration)
|
|
169
|
+
*
|
|
170
|
+
* This sets the complete route manifest from a runtime cache.
|
|
171
|
+
* The cached manifest includes all routes (including lazy includes)
|
|
172
|
+
* and takes precedence over the incrementally-built globalRouteMap.
|
|
173
|
+
*
|
|
174
|
+
* @param manifest - The complete route manifest to cache
|
|
175
|
+
*/
|
|
176
|
+
export function setCachedManifest(manifest: Record<string, string>): void {
|
|
177
|
+
cachedManifest = manifest;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Check if a cached manifest is loaded
|
|
182
|
+
*
|
|
183
|
+
* @returns true if a complete manifest is available
|
|
184
|
+
*/
|
|
185
|
+
export function hasCachedManifest(): boolean {
|
|
186
|
+
return cachedManifest !== null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Clear the cached manifest (for testing)
|
|
191
|
+
*/
|
|
192
|
+
export function clearCachedManifest(): void {
|
|
193
|
+
cachedManifest = null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Set pre-computed route entries from build-time data.
|
|
198
|
+
*
|
|
199
|
+
* Each entry corresponds to a leaf node in the prefix tree (no nested includes).
|
|
200
|
+
* evaluateLazyEntry() checks these before running the handler, avoiding the
|
|
201
|
+
* 5-50ms cost of handler evaluation for route matching on the first request.
|
|
202
|
+
*
|
|
203
|
+
* @param entries - Array of { staticPrefix, routes } from build-time prefix tree leaves
|
|
204
|
+
*/
|
|
205
|
+
export function setPrecomputedEntries(
|
|
206
|
+
entries: Array<{ staticPrefix: string; routes: Record<string, string> }> | null,
|
|
207
|
+
): void {
|
|
208
|
+
cachedPrecomputedEntries = entries;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Get pre-computed route entries (if available)
|
|
213
|
+
*/
|
|
214
|
+
export function getPrecomputedEntries(): typeof cachedPrecomputedEntries {
|
|
215
|
+
return cachedPrecomputedEntries;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Route trie for O(path_length) matching at runtime.
|
|
219
|
+
// Built at build time from the route manifest and serialized into the virtual module.
|
|
220
|
+
let cachedRouteTrie: import("./build/route-trie.js").TrieNode | null = null;
|
|
221
|
+
|
|
222
|
+
export function setRouteTrie(trie: typeof cachedRouteTrie): void {
|
|
223
|
+
cachedRouteTrie = trie;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function getRouteTrie(): typeof cachedRouteTrie {
|
|
227
|
+
return cachedRouteTrie;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Dev-mode manifest readiness gate.
|
|
231
|
+
// The Vite discovery plugin calls setManifestReadyPromise() before starting
|
|
232
|
+
// discovery, and resolves it when discovery completes. The handler awaits
|
|
233
|
+
// waitForManifestReady() on first request if the manifest isn't yet available.
|
|
234
|
+
let manifestReadyPromise: Promise<void> | null = null;
|
|
235
|
+
|
|
236
|
+
export function setManifestReadyPromise(promise: Promise<void>): void {
|
|
237
|
+
manifestReadyPromise = promise;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function waitForManifestReady(): Promise<void> | null {
|
|
241
|
+
return manifestReadyPromise;
|
|
242
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for route system items
|
|
3
|
+
* These are extracted separately to avoid circular dependencies
|
|
4
|
+
* and to prevent bundling server-only code in client bundles
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Branded return types for route helpers
|
|
9
|
+
*/
|
|
10
|
+
export declare const LayoutBrand: unique symbol;
|
|
11
|
+
export declare const RouteBrand: unique symbol;
|
|
12
|
+
export declare const ParallelBrand: unique symbol;
|
|
13
|
+
export declare const InterceptBrand: unique symbol;
|
|
14
|
+
export declare const MiddlewareBrand: unique symbol;
|
|
15
|
+
export declare const RevalidateBrand: unique symbol;
|
|
16
|
+
export declare const LoaderBrand: unique symbol;
|
|
17
|
+
export declare const LoadingBrand: unique symbol;
|
|
18
|
+
export declare const ErrorBoundaryBrand: unique symbol;
|
|
19
|
+
export declare const NotFoundBoundaryBrand: unique symbol;
|
|
20
|
+
export declare const WhenBrand: unique symbol;
|
|
21
|
+
export declare const CacheBrand: unique symbol;
|
|
22
|
+
export declare const IncludeBrand: unique symbol;
|
|
23
|
+
export declare const UrlPatternsBrand: unique symbol;
|
|
24
|
+
|
|
25
|
+
export type LayoutItem = {
|
|
26
|
+
name: string;
|
|
27
|
+
type: "layout";
|
|
28
|
+
uses?: AllUseItems[];
|
|
29
|
+
[LayoutBrand]: void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Typed layout item that carries child routes as phantom type
|
|
34
|
+
* Used for type inference in urls() API
|
|
35
|
+
*/
|
|
36
|
+
export type TypedLayoutItem<
|
|
37
|
+
TChildRoutes extends Record<string, string> = Record<string, string>,
|
|
38
|
+
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
39
|
+
> = LayoutItem & {
|
|
40
|
+
readonly __childRoutes?: TChildRoutes;
|
|
41
|
+
readonly __childResponses?: TChildResponses;
|
|
42
|
+
};
|
|
43
|
+
export type RouteItem = {
|
|
44
|
+
name: string;
|
|
45
|
+
type: "route";
|
|
46
|
+
uses?: AllUseItems[];
|
|
47
|
+
[RouteBrand]: void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Typed route item that carries route name and pattern as phantom types
|
|
52
|
+
* Used for type inference in urls() API
|
|
53
|
+
*/
|
|
54
|
+
export type TypedRouteItem<
|
|
55
|
+
TName extends string = string,
|
|
56
|
+
TPattern extends string = string,
|
|
57
|
+
TData = unknown,
|
|
58
|
+
> = RouteItem & {
|
|
59
|
+
readonly __name?: TName;
|
|
60
|
+
readonly __pattern?: TPattern;
|
|
61
|
+
readonly __data?: TData;
|
|
62
|
+
};
|
|
63
|
+
export type ParallelItem = {
|
|
64
|
+
name: string;
|
|
65
|
+
type: "parallel";
|
|
66
|
+
uses?: ParallelUseItem[];
|
|
67
|
+
[ParallelBrand]: void;
|
|
68
|
+
};
|
|
69
|
+
export type InterceptItem = {
|
|
70
|
+
name: string;
|
|
71
|
+
type: "intercept";
|
|
72
|
+
uses?: InterceptUseItem[];
|
|
73
|
+
[InterceptBrand]: void;
|
|
74
|
+
};
|
|
75
|
+
export type LoaderItem = {
|
|
76
|
+
name: string;
|
|
77
|
+
type: "loader";
|
|
78
|
+
uses?: LoaderUseItem[];
|
|
79
|
+
[LoaderBrand]: void;
|
|
80
|
+
};
|
|
81
|
+
export type MiddlewareItem = {
|
|
82
|
+
name: string;
|
|
83
|
+
type: "middleware";
|
|
84
|
+
uses?: AllUseItems[];
|
|
85
|
+
[MiddlewareBrand]: void;
|
|
86
|
+
};
|
|
87
|
+
export type RevalidateItem = {
|
|
88
|
+
name: string;
|
|
89
|
+
type: "revalidate";
|
|
90
|
+
uses?: AllUseItems[];
|
|
91
|
+
[RevalidateBrand]: void;
|
|
92
|
+
};
|
|
93
|
+
export type LoadingItem = {
|
|
94
|
+
name: string;
|
|
95
|
+
type: "loading";
|
|
96
|
+
[LoadingBrand]: void;
|
|
97
|
+
};
|
|
98
|
+
export type ErrorBoundaryItem = {
|
|
99
|
+
name: string;
|
|
100
|
+
type: "errorBoundary";
|
|
101
|
+
uses?: AllUseItems[];
|
|
102
|
+
[ErrorBoundaryBrand]: void;
|
|
103
|
+
};
|
|
104
|
+
export type NotFoundBoundaryItem = {
|
|
105
|
+
name: string;
|
|
106
|
+
type: "notFoundBoundary";
|
|
107
|
+
uses?: AllUseItems[];
|
|
108
|
+
[NotFoundBoundaryBrand]: void;
|
|
109
|
+
};
|
|
110
|
+
export type WhenItem = {
|
|
111
|
+
name: string;
|
|
112
|
+
type: "when";
|
|
113
|
+
[WhenBrand]: void;
|
|
114
|
+
};
|
|
115
|
+
export type CacheItem = {
|
|
116
|
+
name: string;
|
|
117
|
+
type: "cache";
|
|
118
|
+
uses?: AllUseItems[];
|
|
119
|
+
[CacheBrand]: void;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Typed cache item that carries child routes as phantom type
|
|
124
|
+
* Used for type inference in urls() API
|
|
125
|
+
*/
|
|
126
|
+
export type TypedCacheItem<
|
|
127
|
+
TChildRoutes extends Record<string, string> = Record<string, string>,
|
|
128
|
+
TChildResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
129
|
+
> = CacheItem & {
|
|
130
|
+
readonly __childRoutes?: TChildRoutes;
|
|
131
|
+
readonly __childResponses?: TChildResponses;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Include item for URL pattern composition (used by urls() API)
|
|
136
|
+
*/
|
|
137
|
+
export type IncludeItem = {
|
|
138
|
+
type: "include";
|
|
139
|
+
name: string;
|
|
140
|
+
prefix: string;
|
|
141
|
+
patterns: unknown; // UrlPatterns - avoid circular ref
|
|
142
|
+
options?: { name?: string; lazy?: boolean };
|
|
143
|
+
/** Whether this include should be lazily evaluated on first request */
|
|
144
|
+
lazy?: boolean;
|
|
145
|
+
/** Captured context for deferred lazy evaluation */
|
|
146
|
+
_lazyContext?: {
|
|
147
|
+
urlPrefix: string;
|
|
148
|
+
namePrefix: string | undefined;
|
|
149
|
+
parent: unknown; // EntryData - avoid circular import
|
|
150
|
+
};
|
|
151
|
+
[IncludeBrand]: void;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Typed include item that carries nested routes as phantom type
|
|
156
|
+
* Used for type inference in urls() API
|
|
157
|
+
*/
|
|
158
|
+
export type TypedIncludeItem<
|
|
159
|
+
TRoutes extends Record<string, string> = Record<string, string>,
|
|
160
|
+
TNamePrefix extends string = string,
|
|
161
|
+
TUrlPrefix extends string = string,
|
|
162
|
+
TResponses extends Record<string, unknown> = Record<string, unknown>,
|
|
163
|
+
> = IncludeItem & {
|
|
164
|
+
readonly __routes?: TRoutes;
|
|
165
|
+
readonly __namePrefix?: TNamePrefix;
|
|
166
|
+
readonly __urlPrefix?: TUrlPrefix;
|
|
167
|
+
readonly __responses?: TResponses;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Union types for use() callbacks
|
|
172
|
+
*/
|
|
173
|
+
export type AllUseItems =
|
|
174
|
+
| LayoutItem
|
|
175
|
+
| RouteItem
|
|
176
|
+
| MiddlewareItem
|
|
177
|
+
| RevalidateItem
|
|
178
|
+
| ParallelItem
|
|
179
|
+
| InterceptItem
|
|
180
|
+
| LoaderItem
|
|
181
|
+
| LoadingItem
|
|
182
|
+
| ErrorBoundaryItem
|
|
183
|
+
| NotFoundBoundaryItem
|
|
184
|
+
| CacheItem
|
|
185
|
+
| IncludeItem;
|
|
186
|
+
|
|
187
|
+
/** Items that can be used inside a layout callback */
|
|
188
|
+
export type LayoutUseItem = AllUseItems;
|
|
189
|
+
export type RouteUseItem =
|
|
190
|
+
| LayoutItem
|
|
191
|
+
| ParallelItem
|
|
192
|
+
| InterceptItem
|
|
193
|
+
| MiddlewareItem
|
|
194
|
+
| RevalidateItem
|
|
195
|
+
| LoaderItem
|
|
196
|
+
| LoadingItem
|
|
197
|
+
| ErrorBoundaryItem
|
|
198
|
+
| NotFoundBoundaryItem
|
|
199
|
+
| CacheItem;
|
|
200
|
+
/** Items that can be used inside a response route (path.json(), etc.) */
|
|
201
|
+
export type ResponseRouteUseItem =
|
|
202
|
+
| MiddlewareItem
|
|
203
|
+
| CacheItem;
|
|
204
|
+
export type ParallelUseItem =
|
|
205
|
+
| RevalidateItem
|
|
206
|
+
| LoaderItem
|
|
207
|
+
| LoadingItem
|
|
208
|
+
| ErrorBoundaryItem
|
|
209
|
+
| NotFoundBoundaryItem;
|
|
210
|
+
export type InterceptUseItem =
|
|
211
|
+
| MiddlewareItem
|
|
212
|
+
| RevalidateItem
|
|
213
|
+
| LoaderItem
|
|
214
|
+
| LoadingItem
|
|
215
|
+
| ErrorBoundaryItem
|
|
216
|
+
| NotFoundBoundaryItem
|
|
217
|
+
| LayoutItem
|
|
218
|
+
| RouteItem
|
|
219
|
+
| WhenItem;
|
|
220
|
+
export type LoaderUseItem = RevalidateItem | CacheItem;
|