@rangojs/router 0.0.0-experimental.fa8a383a → 0.0.0-experimental.fb4fdc18
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/README.md +188 -35
- package/dist/bin/rango.js +130 -47
- package/dist/vite/index.js +1884 -537
- package/dist/vite/index.js.bak +5448 -0
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +7 -5
- package/skills/breadcrumbs/SKILL.md +3 -1
- package/skills/cache-guide/SKILL.md +32 -0
- package/skills/caching/SKILL.md +8 -0
- package/skills/handler-use/SKILL.md +362 -0
- package/skills/hooks/SKILL.md +33 -20
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +20 -0
- package/skills/layout/SKILL.md +22 -0
- package/skills/links/SKILL.md +93 -17
- package/skills/loader/SKILL.md +123 -46
- package/skills/middleware/SKILL.md +36 -3
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/parallel/SKILL.md +133 -0
- package/skills/prerender/SKILL.md +110 -68
- package/skills/rango/SKILL.md +26 -22
- package/skills/response-routes/SKILL.md +8 -0
- package/skills/route/SKILL.md +75 -0
- package/skills/router-setup/SKILL.md +87 -2
- package/skills/server-actions/SKILL.md +739 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/typesafety/SKILL.md +19 -1
- package/src/__internal.ts +1 -1
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +44 -4
- package/src/browser/navigation-bridge.ts +95 -7
- package/src/browser/navigation-client.ts +128 -53
- package/src/browser/navigation-store.ts +68 -9
- package/src/browser/partial-update.ts +93 -12
- package/src/browser/prefetch/cache.ts +129 -21
- package/src/browser/prefetch/fetch.ts +156 -18
- package/src/browser/prefetch/queue.ts +92 -29
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +72 -8
- package/src/browser/react/NavigationProvider.tsx +82 -21
- package/src/browser/react/context.ts +7 -2
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/use-handle.ts +9 -58
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +17 -4
- package/src/browser/react/use-router.ts +29 -9
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/rsc-router.tsx +60 -9
- package/src/browser/scroll-restoration.ts +10 -8
- package/src/browser/segment-reconciler.ts +36 -14
- package/src/browser/server-action-bridge.ts +8 -6
- package/src/browser/types.ts +46 -5
- package/src/build/generate-manifest.ts +6 -6
- package/src/build/generate-route-types.ts +3 -0
- package/src/build/route-trie.ts +52 -25
- package/src/build/route-types/include-resolution.ts +8 -1
- package/src/build/route-types/router-processing.ts +211 -72
- package/src/build/route-types/scan-filter.ts +8 -1
- package/src/cache/cache-runtime.ts +15 -11
- package/src/cache/cache-scope.ts +46 -5
- package/src/cache/cf/cf-cache-store.ts +5 -7
- package/src/cache/taint.ts +55 -0
- package/src/client.tsx +84 -230
- package/src/context-var.ts +72 -2
- package/src/handle.ts +40 -0
- package/src/index.rsc.ts +6 -1
- package/src/index.ts +49 -6
- package/src/outlet-context.ts +1 -1
- package/src/prerender/store.ts +5 -4
- package/src/prerender.ts +138 -77
- package/src/response-utils.ts +28 -0
- package/src/reverse.ts +28 -2
- package/src/route-definition/dsl-helpers.ts +210 -35
- package/src/route-definition/helpers-types.ts +73 -20
- package/src/route-definition/index.ts +3 -0
- package/src/route-definition/redirect.ts +9 -1
- package/src/route-definition/resolve-handler-use.ts +155 -0
- package/src/route-types.ts +18 -0
- package/src/router/content-negotiation.ts +100 -1
- package/src/router/handler-context.ts +102 -25
- package/src/router/intercept-resolution.ts +9 -4
- package/src/router/lazy-includes.ts +6 -6
- package/src/router/loader-resolution.ts +159 -21
- package/src/router/manifest.ts +22 -13
- package/src/router/match-api.ts +128 -192
- package/src/router/match-handlers.ts +1 -0
- package/src/router/match-middleware/background-revalidation.ts +12 -1
- package/src/router/match-middleware/cache-lookup.ts +74 -14
- package/src/router/match-middleware/cache-store.ts +21 -4
- package/src/router/match-middleware/segment-resolution.ts +53 -0
- package/src/router/match-result.ts +112 -9
- package/src/router/metrics.ts +6 -1
- package/src/router/middleware-types.ts +20 -33
- package/src/router/middleware.ts +56 -12
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +101 -17
- package/src/router/prerender-match.ts +110 -10
- package/src/router/preview-match.ts +30 -102
- package/src/router/request-classification.ts +310 -0
- package/src/router/revalidation.ts +15 -1
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +1 -0
- package/src/router/router-interfaces.ts +36 -4
- package/src/router/router-options.ts +37 -11
- package/src/router/segment-resolution/fresh.ts +114 -18
- package/src/router/segment-resolution/helpers.ts +29 -24
- package/src/router/segment-resolution/revalidation.ts +257 -127
- package/src/router/trie-matching.ts +18 -13
- package/src/router/types.ts +1 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +55 -7
- package/src/rsc/handler.ts +478 -383
- package/src/rsc/helpers.ts +69 -41
- package/src/rsc/loader-fetch.ts +23 -3
- package/src/rsc/manifest-init.ts +5 -1
- package/src/rsc/progressive-enhancement.ts +18 -2
- package/src/rsc/response-route-handler.ts +14 -1
- package/src/rsc/rsc-rendering.ts +20 -1
- package/src/rsc/server-action.ts +12 -0
- package/src/rsc/ssr-setup.ts +2 -2
- package/src/rsc/types.ts +15 -1
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +22 -62
- package/src/server/context.ts +76 -4
- package/src/server/handle-store.ts +19 -0
- package/src/server/loader-registry.ts +9 -8
- package/src/server/request-context.ts +185 -57
- package/src/ssr/index.tsx +8 -1
- package/src/static-handler.ts +18 -6
- package/src/types/cache-types.ts +4 -4
- package/src/types/handler-context.ts +145 -68
- package/src/types/loader-types.ts +41 -15
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-entry.ts +12 -1
- package/src/types/segments.ts +18 -1
- package/src/urls/include-helper.ts +24 -14
- package/src/urls/path-helper-types.ts +39 -6
- package/src/urls/path-helper.ts +47 -12
- package/src/urls/pattern-types.ts +12 -0
- package/src/urls/response-types.ts +18 -16
- package/src/use-loader.tsx +77 -5
- package/src/vite/debug.ts +184 -0
- package/src/vite/discovery/bundle-postprocess.ts +30 -33
- package/src/vite/discovery/discover-routers.ts +36 -4
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +175 -74
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +13 -4
- package/src/vite/index.ts +4 -0
- package/src/vite/plugin-types.ts +60 -5
- package/src/vite/plugins/cjs-to-esm.ts +5 -0
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +16 -4
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/expose-action-id.ts +52 -28
- package/src/vite/plugins/expose-id-utils.ts +12 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +30 -0
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +563 -316
- package/src/vite/plugins/performance-tracks.ts +96 -0
- package/src/vite/plugins/refresh-cmd.ts +88 -26
- package/src/vite/plugins/use-cache-transform.ts +56 -43
- package/src/vite/plugins/version-injector.ts +37 -11
- package/src/vite/rango.ts +63 -11
- package/src/vite/router-discovery.ts +732 -86
- package/src/vite/utils/banner.ts +1 -1
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +38 -5
- package/src/vite/utils/shared-utils.ts +3 -2
package/src/browser/types.ts
CHANGED
|
@@ -32,10 +32,19 @@ export type HandleData = Record<string, Record<string, unknown[]>>;
|
|
|
32
32
|
export interface RscMetadata {
|
|
33
33
|
pathname: string;
|
|
34
34
|
segments: ResolvedSegment[];
|
|
35
|
+
/** Router instance ID. When this changes between navigations, the client
|
|
36
|
+
* forces a full tree replacement (app switch via host router). */
|
|
37
|
+
routerId?: string;
|
|
35
38
|
isPartial?: boolean;
|
|
36
39
|
isError?: boolean;
|
|
37
40
|
matched?: string[];
|
|
38
41
|
diff?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* All segment ids re-resolved on the server, including null-component
|
|
44
|
+
* ones excluded from `segments`/`diff`. Drives client-side handle-bucket
|
|
45
|
+
* cleanup. Superset of `diff`. See MatchResult.resolvedIds.
|
|
46
|
+
*/
|
|
47
|
+
resolvedIds?: string[];
|
|
39
48
|
/** Merged route params from the matched route */
|
|
40
49
|
params?: Record<string, string>;
|
|
41
50
|
/**
|
|
@@ -70,6 +79,8 @@ export interface RscMetadata {
|
|
|
70
79
|
* Included when theme is enabled in router config.
|
|
71
80
|
*/
|
|
72
81
|
initialTheme?: Theme;
|
|
82
|
+
/** URL prefix for all routes (from createRouter({ basename })). */
|
|
83
|
+
basename?: string;
|
|
73
84
|
/** Whether connection warmup is enabled */
|
|
74
85
|
warmupEnabled?: boolean;
|
|
75
86
|
/** Server-side redirect with optional state (for partial requests) */
|
|
@@ -341,7 +352,13 @@ export type ReadonlyURLSearchParams = Omit<
|
|
|
341
352
|
export interface RscBrowserDependencies {
|
|
342
353
|
createFromFetch: <T>(
|
|
343
354
|
response: Promise<Response>,
|
|
344
|
-
options?: {
|
|
355
|
+
options?: {
|
|
356
|
+
temporaryReferences?: any;
|
|
357
|
+
findSourceMapURL?: (
|
|
358
|
+
filename: string,
|
|
359
|
+
environmentName: string,
|
|
360
|
+
) => string | null;
|
|
361
|
+
},
|
|
345
362
|
) => Promise<T>;
|
|
346
363
|
createFromReadableStream: <T>(stream: ReadableStream) => Promise<T>;
|
|
347
364
|
encodeReply: (
|
|
@@ -403,16 +420,25 @@ export interface NavigationStore {
|
|
|
403
420
|
segments: ResolvedSegment[],
|
|
404
421
|
handleData?: HandleData,
|
|
405
422
|
): void;
|
|
406
|
-
getCachedSegments(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
423
|
+
getCachedSegments(historyKey: string):
|
|
424
|
+
| {
|
|
425
|
+
segments: ResolvedSegment[];
|
|
426
|
+
stale: boolean;
|
|
427
|
+
handleData?: HandleData;
|
|
428
|
+
routerId?: string;
|
|
429
|
+
}
|
|
410
430
|
| undefined;
|
|
411
431
|
hasHistoryCache(historyKey: string): boolean;
|
|
412
432
|
updateCacheHandleData(historyKey: string, handleData: HandleData): void;
|
|
413
433
|
markCacheAsStale(): void;
|
|
414
434
|
markCacheAsStaleAndBroadcast(): void;
|
|
415
435
|
clearHistoryCache(): void;
|
|
436
|
+
/**
|
|
437
|
+
* Clear this tab's nav + prefetch caches without broadcasting or rotating
|
|
438
|
+
* shared state. Intended for app-switch transitions that affect only this
|
|
439
|
+
* tab's session.
|
|
440
|
+
*/
|
|
441
|
+
clearHistoryCacheLocal(): void;
|
|
416
442
|
broadcastCacheInvalidation(): void;
|
|
417
443
|
|
|
418
444
|
// Cross-tab refresh callback (set by navigation bridge)
|
|
@@ -422,6 +448,10 @@ export interface NavigationStore {
|
|
|
422
448
|
getInterceptSourceUrl(): string | null;
|
|
423
449
|
setInterceptSourceUrl(url: string | null): void;
|
|
424
450
|
|
|
451
|
+
// Router identity tracking (for cross-app navigation detection)
|
|
452
|
+
getRouterId?(): string | undefined;
|
|
453
|
+
setRouterId?(id: string): void;
|
|
454
|
+
|
|
425
455
|
// UI update notifications
|
|
426
456
|
onUpdate(callback: UpdateSubscriber): () => void;
|
|
427
457
|
emitUpdate(update: NavigationUpdate): void;
|
|
@@ -452,6 +482,8 @@ export interface FetchPartialOptions {
|
|
|
452
482
|
interceptSourceUrl?: string;
|
|
453
483
|
/** RSC version for cache invalidation detection */
|
|
454
484
|
version?: string;
|
|
485
|
+
/** Current router ID — server detects app switch and returns full response */
|
|
486
|
+
routerId?: string;
|
|
455
487
|
/** If true, this is an HMR refetch - server should invalidate manifest cache */
|
|
456
488
|
hmr?: boolean;
|
|
457
489
|
}
|
|
@@ -520,6 +552,15 @@ export interface NavigationBridge {
|
|
|
520
552
|
refresh(): Promise<void>;
|
|
521
553
|
handlePopstate(): Promise<void>;
|
|
522
554
|
registerLinkInterception(): () => void;
|
|
555
|
+
/** Update the RSC version (e.g. after HMR). Clears prefetch cache. */
|
|
556
|
+
updateVersion(newVersion: string): void;
|
|
557
|
+
/**
|
|
558
|
+
* Replace the active app-shell snapshot (rootLayout, basename, version)
|
|
559
|
+
* atomically. Used on cross-app navigations when the response's routerId
|
|
560
|
+
* indicates the user entered a different app. Theme, warmup, and prefetch
|
|
561
|
+
* TTL are document-lifetime and not part of the shell.
|
|
562
|
+
*/
|
|
563
|
+
updateAppShell(next: import("./app-shell.js").AppShell): void;
|
|
523
564
|
}
|
|
524
565
|
|
|
525
566
|
/**
|
|
@@ -45,7 +45,7 @@ export interface GeneratedManifest {
|
|
|
45
45
|
routeTrailingSlash?: Record<string, string>;
|
|
46
46
|
/** Route names using Prerender (for dev-mode Node.js delegation) */
|
|
47
47
|
prerenderRoutes?: string[];
|
|
48
|
-
/** Route names with
|
|
48
|
+
/** Route names wrapped with Passthrough() (live handler for runtime fallback) */
|
|
49
49
|
passthroughRoutes?: string[];
|
|
50
50
|
/** Route name → response type for non-RSC routes */
|
|
51
51
|
responseTypeRoutes?: Record<string, string>;
|
|
@@ -150,10 +150,7 @@ function buildPrefixTreeNode(
|
|
|
150
150
|
if (prerenderDefs && entry.prerenderDef) {
|
|
151
151
|
prerenderDefs[name] = entry.prerenderDef;
|
|
152
152
|
}
|
|
153
|
-
if (
|
|
154
|
-
passthroughRoutes &&
|
|
155
|
-
entry.prerenderDef?.options?.passthrough === true
|
|
156
|
-
) {
|
|
153
|
+
if (passthroughRoutes && entry.isPassthrough === true) {
|
|
157
154
|
passthroughRoutes.push(name);
|
|
158
155
|
}
|
|
159
156
|
}
|
|
@@ -285,6 +282,7 @@ export function generateManifest<TEnv>(
|
|
|
285
282
|
export function generateManifestFull<TEnv>(
|
|
286
283
|
urlpatterns: UrlPatterns<TEnv, any>,
|
|
287
284
|
mountIndex: number = 0,
|
|
285
|
+
options?: { urlPrefix?: string },
|
|
288
286
|
): FullManifest {
|
|
289
287
|
const routeManifest: Record<string, string> = {};
|
|
290
288
|
const routeAncestry: Record<string, string[]> = {};
|
|
@@ -310,6 +308,8 @@ export function generateManifestFull<TEnv>(
|
|
|
310
308
|
counters: {},
|
|
311
309
|
mountIndex,
|
|
312
310
|
trackedIncludes, // Enable include tracking
|
|
311
|
+
// basename sets the initial URL prefix for all path() registrations
|
|
312
|
+
...(options?.urlPrefix ? { urlPrefix: options.urlPrefix } : {}),
|
|
313
313
|
},
|
|
314
314
|
() => {
|
|
315
315
|
const helpers = createRouteHelpers();
|
|
@@ -347,7 +347,7 @@ export function generateManifestFull<TEnv>(
|
|
|
347
347
|
if (entry.prerenderDef) {
|
|
348
348
|
prerenderDefs[name] = entry.prerenderDef;
|
|
349
349
|
}
|
|
350
|
-
if (entry.
|
|
350
|
+
if (entry.isPassthrough === true) {
|
|
351
351
|
passthroughRoutes.push(name);
|
|
352
352
|
}
|
|
353
353
|
}
|
|
@@ -25,6 +25,9 @@ export {
|
|
|
25
25
|
} from "./route-types/include-resolution.js";
|
|
26
26
|
export {
|
|
27
27
|
extractUrlsVariableFromRouter,
|
|
28
|
+
extractUrlsFromRouter,
|
|
29
|
+
extractBasenameFromRouter,
|
|
30
|
+
type UrlsExtractionResult,
|
|
28
31
|
buildCombinedRouteMapForRouterFile,
|
|
29
32
|
detectUnresolvableIncludes,
|
|
30
33
|
detectUnresolvableIncludesForUrlsFile,
|
package/src/build/route-trie.ts
CHANGED
|
@@ -20,7 +20,8 @@ export interface TrieLeaf {
|
|
|
20
20
|
sp: string;
|
|
21
21
|
/** Ancestry shortCodes from root to route [M0L0, M0L0L0, M0L0L0R499] */
|
|
22
22
|
a: string[];
|
|
23
|
-
/** Optional param names
|
|
23
|
+
/** Optional param names declared on the route. Absent params are
|
|
24
|
+
* omitted from the matched params record (read as `undefined`). */
|
|
24
25
|
op?: string[];
|
|
25
26
|
/** Constraint validation: paramName -> allowed values */
|
|
26
27
|
cv?: Record<string, string[]>;
|
|
@@ -98,8 +99,14 @@ export function buildRouteTrie(
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* Insert a route into the trie
|
|
102
|
-
*
|
|
102
|
+
* Insert a route into the trie. Optional params expand into two branches at
|
|
103
|
+
* registration time (skip-first, then present), so each terminal lives at the
|
|
104
|
+
* correct depth for its number of bound params and carries a branch-local
|
|
105
|
+
* `pa` listing only those names. The trie's single-slot `node.p` is reused
|
|
106
|
+
* across branches because matching ignores `node.p.n` — the leaf's `pa` is
|
|
107
|
+
* the source of truth for naming. Skip-first ordering lets `mergeLeaf`'s
|
|
108
|
+
* last-wins rule produce greedy-leftmost semantics for free at any shared
|
|
109
|
+
* terminal depth.
|
|
103
110
|
*/
|
|
104
111
|
function insertRoute(
|
|
105
112
|
node: TrieNode,
|
|
@@ -107,14 +114,13 @@ function insertRoute(
|
|
|
107
114
|
index: number,
|
|
108
115
|
leaf: Omit<TrieLeaf, "op" | "cv" | "pa">,
|
|
109
116
|
): void {
|
|
110
|
-
//
|
|
111
|
-
|
|
117
|
+
// op (full optional list) and cv (full constraint map) are route-level and
|
|
118
|
+
// identical on every terminal, so compute them once on the shared base.
|
|
112
119
|
const optionalParams: string[] = [];
|
|
113
120
|
const constraints: Record<string, string[]> = {};
|
|
114
121
|
|
|
115
122
|
for (const seg of segments) {
|
|
116
123
|
if (seg.type === "param") {
|
|
117
|
-
paramNames.push(seg.value);
|
|
118
124
|
if (seg.optional) {
|
|
119
125
|
optionalParams.push(seg.value);
|
|
120
126
|
}
|
|
@@ -124,21 +130,15 @@ function insertRoute(
|
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
|
|
127
|
-
const
|
|
133
|
+
const leafBase: Omit<TrieLeaf, "pa"> = {
|
|
128
134
|
...leaf,
|
|
129
|
-
...(paramNames.length > 0 ? { pa: paramNames } : {}),
|
|
130
135
|
...(optionalParams.length > 0 ? { op: optionalParams } : {}),
|
|
131
136
|
...(Object.keys(constraints).length > 0 ? { cv: constraints } : {}),
|
|
132
137
|
};
|
|
133
138
|
|
|
134
|
-
insertSegments(node, segments, index,
|
|
139
|
+
insertSegments(node, segments, index, leafBase, []);
|
|
135
140
|
}
|
|
136
141
|
|
|
137
|
-
/**
|
|
138
|
-
* Recursively insert segments into the trie.
|
|
139
|
-
* For optional params, we add a terminal at the current node (param absent)
|
|
140
|
-
* AND continue inserting into the param child (param present).
|
|
141
|
-
*/
|
|
142
142
|
/**
|
|
143
143
|
* Extract ancestry map from a built trie by visiting all leaf nodes.
|
|
144
144
|
* Returns { routeName: ancestryShortCodes[] } for every route in the trie.
|
|
@@ -218,15 +218,25 @@ function mergeLeaf(node: TrieNode, leaf: TrieLeaf): void {
|
|
|
218
218
|
node.r = mergeLeaves(node.r, leaf);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
function buildLeaf(
|
|
222
|
+
leafBase: Omit<TrieLeaf, "pa">,
|
|
223
|
+
paramNames: string[],
|
|
224
|
+
): TrieLeaf {
|
|
225
|
+
return paramNames.length > 0
|
|
226
|
+
? { ...leafBase, pa: [...paramNames] }
|
|
227
|
+
: { ...leafBase };
|
|
228
|
+
}
|
|
229
|
+
|
|
221
230
|
function insertSegments(
|
|
222
231
|
node: TrieNode,
|
|
223
232
|
segments: ParsedSegment[],
|
|
224
233
|
index: number,
|
|
225
|
-
|
|
234
|
+
leafBase: Omit<TrieLeaf, "pa">,
|
|
235
|
+
paramNames: string[],
|
|
226
236
|
): void {
|
|
227
|
-
// Base case: all segments consumed, add terminal
|
|
237
|
+
// Base case: all segments consumed, add terminal with branch-local pa
|
|
228
238
|
if (index >= segments.length) {
|
|
229
|
-
mergeLeaf(node,
|
|
239
|
+
mergeLeaf(node, buildLeaf(leafBase, paramNames));
|
|
230
240
|
return;
|
|
231
241
|
}
|
|
232
242
|
|
|
@@ -235,12 +245,19 @@ function insertSegments(
|
|
|
235
245
|
if (segment.type === "static") {
|
|
236
246
|
if (!node.s) node.s = {};
|
|
237
247
|
if (!node.s[segment.value]) node.s[segment.value] = {};
|
|
238
|
-
insertSegments(
|
|
248
|
+
insertSegments(
|
|
249
|
+
node.s[segment.value],
|
|
250
|
+
segments,
|
|
251
|
+
index + 1,
|
|
252
|
+
leafBase,
|
|
253
|
+
paramNames,
|
|
254
|
+
);
|
|
239
255
|
} else if (segment.type === "param") {
|
|
240
256
|
if (segment.optional) {
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
//
|
|
257
|
+
// SKIP first: continue at the same node without binding this name.
|
|
258
|
+
// Skip-first ordering means the present-branch's TAKE overwrites any
|
|
259
|
+
// shared terminal later, giving greedy-leftmost semantics.
|
|
260
|
+
insertSegments(node, segments, index + 1, leafBase, paramNames);
|
|
244
261
|
}
|
|
245
262
|
if (segment.suffix) {
|
|
246
263
|
// Suffix param: keyed by suffix string (e.g., ".html")
|
|
@@ -248,16 +265,26 @@ function insertSegments(
|
|
|
248
265
|
if (!node.xp[segment.suffix]) {
|
|
249
266
|
node.xp[segment.suffix] = { n: segment.value, c: {} };
|
|
250
267
|
}
|
|
251
|
-
insertSegments(node.xp[segment.suffix].c, segments, index + 1,
|
|
268
|
+
insertSegments(node.xp[segment.suffix].c, segments, index + 1, leafBase, [
|
|
269
|
+
...paramNames,
|
|
270
|
+
segment.value,
|
|
271
|
+
]);
|
|
252
272
|
} else {
|
|
253
273
|
if (!node.p) {
|
|
254
274
|
node.p = { n: segment.value, c: {} };
|
|
255
275
|
}
|
|
256
|
-
insertSegments(node.p.c, segments, index + 1,
|
|
276
|
+
insertSegments(node.p.c, segments, index + 1, leafBase, [
|
|
277
|
+
...paramNames,
|
|
278
|
+
segment.value,
|
|
279
|
+
]);
|
|
257
280
|
}
|
|
258
281
|
} else if (segment.type === "wildcard") {
|
|
259
|
-
// Wildcard consumes all remaining segments
|
|
260
|
-
|
|
282
|
+
// Wildcard consumes all remaining segments. Carry any params bound before
|
|
283
|
+
// the wildcard in pa so they zip correctly against paramValues at match.
|
|
284
|
+
const wildLeaf: TrieLeaf & { pn: string } = {
|
|
285
|
+
...buildLeaf(leafBase, paramNames),
|
|
286
|
+
pn: "*",
|
|
287
|
+
};
|
|
261
288
|
const existing = node.w ? ({ ...node.w } as TrieLeaf) : undefined;
|
|
262
289
|
const merged = mergeLeaves(existing, wildLeaf);
|
|
263
290
|
node.w = merged as TrieLeaf & { pn: string };
|
|
@@ -357,12 +357,17 @@ function buildRouteMapFromBlock(
|
|
|
357
357
|
/**
|
|
358
358
|
* Build route map and search schemas together.
|
|
359
359
|
* Internal helper used by the include resolution path.
|
|
360
|
+
*
|
|
361
|
+
* @param inlineBlock - Optional pre-extracted code block (e.g. from an inline
|
|
362
|
+
* builder function). When provided, variableName is ignored and the block
|
|
363
|
+
* is parsed directly for path()/include() calls.
|
|
360
364
|
*/
|
|
361
365
|
export function buildCombinedRouteMapWithSearch(
|
|
362
366
|
filePath: string,
|
|
363
367
|
variableName?: string,
|
|
364
368
|
visited?: Set<string>,
|
|
365
369
|
diagnosticsOut?: UnresolvableInclude[],
|
|
370
|
+
inlineBlock?: string,
|
|
366
371
|
): {
|
|
367
372
|
routes: Record<string, string>;
|
|
368
373
|
searchSchemas: Record<string, Record<string, string>>;
|
|
@@ -384,7 +389,9 @@ export function buildCombinedRouteMapWithSearch(
|
|
|
384
389
|
}
|
|
385
390
|
|
|
386
391
|
let block: string;
|
|
387
|
-
if (
|
|
392
|
+
if (inlineBlock) {
|
|
393
|
+
block = inlineBlock;
|
|
394
|
+
} else if (variableName) {
|
|
388
395
|
const extracted = extractUrlsBlockForVariable(source, variableName);
|
|
389
396
|
if (!extracted) return { routes: {}, searchSchemas: {} };
|
|
390
397
|
block = extracted;
|