@tanstack/router-core 1.136.3 → 1.136.5
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/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -0
- package/dist/cjs/index.cjs +0 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -4
- package/dist/cjs/lru-cache.cjs +5 -0
- package/dist/cjs/lru-cache.cjs.map +1 -1
- package/dist/cjs/lru-cache.d.cts +1 -0
- package/dist/cjs/new-process-route-tree.cjs +655 -0
- package/dist/cjs/new-process-route-tree.cjs.map +1 -0
- package/dist/cjs/new-process-route-tree.d.cts +177 -0
- package/dist/cjs/path.cjs +133 -434
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +3 -39
- package/dist/cjs/router.cjs +47 -98
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +7 -11
- package/dist/cjs/ssr/constants.cjs.map +1 -1
- package/dist/cjs/ssr/constants.d.cts +1 -0
- package/dist/cjs/ssr/ssr-client.cjs +2 -0
- package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
- package/dist/cjs/ssr/ssr-client.d.cts +4 -1
- package/dist/cjs/ssr/ssr-server.cjs +64 -12
- package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
- package/dist/cjs/ssr/tsrScript.cjs +1 -1
- package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
- package/dist/esm/Matches.d.ts +2 -0
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/index.d.ts +1 -4
- package/dist/esm/index.js +1 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lru-cache.d.ts +1 -0
- package/dist/esm/lru-cache.js +5 -0
- package/dist/esm/lru-cache.js.map +1 -1
- package/dist/esm/new-process-route-tree.d.ts +177 -0
- package/dist/esm/new-process-route-tree.js +655 -0
- package/dist/esm/new-process-route-tree.js.map +1 -0
- package/dist/esm/path.d.ts +3 -39
- package/dist/esm/path.js +133 -434
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/router.d.ts +7 -11
- package/dist/esm/router.js +48 -99
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/ssr/constants.d.ts +1 -0
- package/dist/esm/ssr/constants.js.map +1 -1
- package/dist/esm/ssr/ssr-client.d.ts +4 -1
- package/dist/esm/ssr/ssr-client.js +2 -0
- package/dist/esm/ssr/ssr-client.js.map +1 -1
- package/dist/esm/ssr/ssr-server.js +64 -12
- package/dist/esm/ssr/ssr-server.js.map +1 -1
- package/dist/esm/ssr/tsrScript.js +1 -1
- package/dist/esm/ssr/tsrScript.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.ts +2 -0
- package/src/index.ts +0 -6
- package/src/lru-cache.ts +6 -0
- package/src/new-process-route-tree.ts +1036 -0
- package/src/path.ts +168 -639
- package/src/router.ts +58 -126
- package/src/ssr/constants.ts +1 -0
- package/src/ssr/ssr-client.ts +10 -1
- package/src/ssr/ssr-server.ts +69 -12
- package/src/ssr/tsrScript.ts +4 -0
- package/dist/cjs/process-route-tree.cjs +0 -144
- package/dist/cjs/process-route-tree.cjs.map +0 -1
- package/dist/cjs/process-route-tree.d.cts +0 -18
- package/dist/esm/process-route-tree.d.ts +0 -18
- package/dist/esm/process-route-tree.js +0 -144
- package/dist/esm/process-route-tree.js.map +0 -1
- package/src/process-route-tree.ts +0 -241
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { LRUCache } from './lru-cache.js';
|
|
2
|
+
export declare const SEGMENT_TYPE_PATHNAME = 0;
|
|
3
|
+
export declare const SEGMENT_TYPE_PARAM = 1;
|
|
4
|
+
export declare const SEGMENT_TYPE_WILDCARD = 2;
|
|
5
|
+
export declare const SEGMENT_TYPE_OPTIONAL_PARAM = 3;
|
|
6
|
+
export type SegmentKind = typeof SEGMENT_TYPE_PATHNAME | typeof SEGMENT_TYPE_PARAM | typeof SEGMENT_TYPE_WILDCARD | typeof SEGMENT_TYPE_OPTIONAL_PARAM;
|
|
7
|
+
type ParsedSegment = Uint16Array & {
|
|
8
|
+
/** segment type (0 = pathname, 1 = param, 2 = wildcard, 3 = optional param) */
|
|
9
|
+
0: SegmentKind;
|
|
10
|
+
/** index of the end of the prefix */
|
|
11
|
+
1: number;
|
|
12
|
+
/** index of the start of the value */
|
|
13
|
+
2: number;
|
|
14
|
+
/** index of the end of the value */
|
|
15
|
+
3: number;
|
|
16
|
+
/** index of the start of the suffix */
|
|
17
|
+
4: number;
|
|
18
|
+
/** index of the end of the segment */
|
|
19
|
+
5: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Populates the `output` array with the parsed representation of the given `segment` string.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```ts
|
|
26
|
+
* let output
|
|
27
|
+
* let cursor = 0
|
|
28
|
+
* while (cursor < path.length) {
|
|
29
|
+
* output = parseSegment(path, cursor, output)
|
|
30
|
+
* const end = output[5]
|
|
31
|
+
* cursor = end + 1
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* `output` is stored outside to avoid allocations during repeated calls. It doesn't need to be typed
|
|
35
|
+
* or initialized, it will be done automatically.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseSegment(
|
|
38
|
+
/** The full path string containing the segment. */
|
|
39
|
+
path: string,
|
|
40
|
+
/** The starting index of the segment within the path. */
|
|
41
|
+
start: number,
|
|
42
|
+
/** A Uint16Array (length: 6) to populate with the parsed segment data. */
|
|
43
|
+
output?: Uint16Array): ParsedSegment;
|
|
44
|
+
type StaticSegmentNode<T extends RouteLike> = SegmentNode<T> & {
|
|
45
|
+
kind: typeof SEGMENT_TYPE_PATHNAME;
|
|
46
|
+
};
|
|
47
|
+
type DynamicSegmentNode<T extends RouteLike> = SegmentNode<T> & {
|
|
48
|
+
kind: typeof SEGMENT_TYPE_PARAM | typeof SEGMENT_TYPE_WILDCARD | typeof SEGMENT_TYPE_OPTIONAL_PARAM;
|
|
49
|
+
prefix?: string;
|
|
50
|
+
suffix?: string;
|
|
51
|
+
caseSensitive: boolean;
|
|
52
|
+
};
|
|
53
|
+
type AnySegmentNode<T extends RouteLike> = StaticSegmentNode<T> | DynamicSegmentNode<T>;
|
|
54
|
+
type SegmentNode<T extends RouteLike> = {
|
|
55
|
+
kind: SegmentKind;
|
|
56
|
+
/** Static segments (highest priority) */
|
|
57
|
+
static: Map<string, StaticSegmentNode<T>> | null;
|
|
58
|
+
/** Case insensitive static segments (second highest priority) */
|
|
59
|
+
staticInsensitive: Map<string, StaticSegmentNode<T>> | null;
|
|
60
|
+
/** Dynamic segments ($param) */
|
|
61
|
+
dynamic: Array<DynamicSegmentNode<T>> | null;
|
|
62
|
+
/** Optional dynamic segments ({-$param}) */
|
|
63
|
+
optional: Array<DynamicSegmentNode<T>> | null;
|
|
64
|
+
/** Wildcard segments ($ - lowest priority) */
|
|
65
|
+
wildcard: Array<DynamicSegmentNode<T>> | null;
|
|
66
|
+
/** Terminal route (if this path can end here) */
|
|
67
|
+
route: T | null;
|
|
68
|
+
/** The full path for this segment node (will only be valid on leaf nodes) */
|
|
69
|
+
fullPath: string;
|
|
70
|
+
parent: AnySegmentNode<T> | null;
|
|
71
|
+
depth: number;
|
|
72
|
+
/** is it an index route (trailing / path), only valid for nodes with a `route` */
|
|
73
|
+
isIndex: boolean;
|
|
74
|
+
/** Same as `route`, but only present if both an "index route" and a "layout route" exist at this path */
|
|
75
|
+
notFound: T | null;
|
|
76
|
+
};
|
|
77
|
+
type RouteLike = {
|
|
78
|
+
path?: string;
|
|
79
|
+
children?: Array<RouteLike>;
|
|
80
|
+
parentRoute?: RouteLike;
|
|
81
|
+
isRoot?: boolean;
|
|
82
|
+
options?: {
|
|
83
|
+
caseSensitive?: boolean;
|
|
84
|
+
};
|
|
85
|
+
} & ({
|
|
86
|
+
fullPath: string;
|
|
87
|
+
from?: never;
|
|
88
|
+
} | {
|
|
89
|
+
fullPath?: never;
|
|
90
|
+
from: string;
|
|
91
|
+
});
|
|
92
|
+
export type ProcessedTree<TTree extends Extract<RouteLike, {
|
|
93
|
+
fullPath: string;
|
|
94
|
+
}>, TFlat extends Extract<RouteLike, {
|
|
95
|
+
from: string;
|
|
96
|
+
}>, TSingle extends Extract<RouteLike, {
|
|
97
|
+
from: string;
|
|
98
|
+
}>> = {
|
|
99
|
+
/** a representation of the `routeTree` as a segment tree */
|
|
100
|
+
segmentTree: AnySegmentNode<TTree>;
|
|
101
|
+
/** a mini route tree generated from the flat `routeMasks` list */
|
|
102
|
+
masksTree: AnySegmentNode<TFlat> | null;
|
|
103
|
+
/** @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree */
|
|
104
|
+
singleCache: Map<any, AnySegmentNode<TSingle>>;
|
|
105
|
+
/** a cache of route matches from the `segmentTree` */
|
|
106
|
+
matchCache: LRUCache<string, ReturnType<typeof findMatch<TTree>>>;
|
|
107
|
+
/** a cache of route matches from the `masksTree` */
|
|
108
|
+
flatCache: LRUCache<string, ReturnType<typeof findMatch<TFlat>>> | null;
|
|
109
|
+
};
|
|
110
|
+
export declare function processRouteMasks<TRouteLike extends Extract<RouteLike, {
|
|
111
|
+
from: string;
|
|
112
|
+
}>>(routeList: Array<TRouteLike>, processedTree: ProcessedTree<any, TRouteLike, any>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Take an arbitrary list of routes, create a tree from them (if it hasn't been created already), and match a path against it.
|
|
115
|
+
*/
|
|
116
|
+
export declare function findFlatMatch<T extends Extract<RouteLike, {
|
|
117
|
+
from: string;
|
|
118
|
+
}>>(
|
|
119
|
+
/** The path to match. */
|
|
120
|
+
path: string,
|
|
121
|
+
/** The `processedTree` returned by the initial `processRouteTree` call. */
|
|
122
|
+
processedTree: ProcessedTree<any, T, any>): {
|
|
123
|
+
route: T;
|
|
124
|
+
params: Record<string, string>;
|
|
125
|
+
} | null;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated keep until v2 so that `router.matchRoute` can keep not caring about the actual route tree
|
|
128
|
+
*/
|
|
129
|
+
export declare function findSingleMatch(from: string, caseSensitive: boolean, fuzzy: boolean, path: string, processedTree: ProcessedTree<any, any, {
|
|
130
|
+
from: string;
|
|
131
|
+
}>): {
|
|
132
|
+
route: {
|
|
133
|
+
from: string;
|
|
134
|
+
};
|
|
135
|
+
params: Record<string, string>;
|
|
136
|
+
} | null;
|
|
137
|
+
export declare function findRouteMatch<T extends Extract<RouteLike, {
|
|
138
|
+
fullPath: string;
|
|
139
|
+
}>>(
|
|
140
|
+
/** The path to match against the route tree. */
|
|
141
|
+
path: string,
|
|
142
|
+
/** The `processedTree` returned by the initial `processRouteTree` call. */
|
|
143
|
+
processedTree: ProcessedTree<T, any, any>,
|
|
144
|
+
/** If `true`, allows fuzzy matching (partial matches), i.e. which node in the tree would have been an exact match if the `path` had been shorter? */
|
|
145
|
+
fuzzy?: boolean): {
|
|
146
|
+
route: T;
|
|
147
|
+
params: Record<string, string>;
|
|
148
|
+
} | null;
|
|
149
|
+
/** Trim trailing slashes (except preserving root '/'). */
|
|
150
|
+
export declare function trimPathRight(path: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Processes a route tree into a segment trie for efficient path matching.
|
|
153
|
+
* Also builds lookup maps for routes by ID and by trimmed full path.
|
|
154
|
+
*/
|
|
155
|
+
export declare function processRouteTree<TRouteLike extends Extract<RouteLike, {
|
|
156
|
+
fullPath: string;
|
|
157
|
+
}> & {
|
|
158
|
+
id: string;
|
|
159
|
+
}>(
|
|
160
|
+
/** The root of the route tree to process. */
|
|
161
|
+
routeTree: TRouteLike,
|
|
162
|
+
/** Whether matching should be case sensitive by default (overridden by individual route options). */
|
|
163
|
+
caseSensitive?: boolean,
|
|
164
|
+
/** Optional callback invoked for each route during processing. */
|
|
165
|
+
initRoute?: (route: TRouteLike, index: number) => void): {
|
|
166
|
+
/** Should be considered a black box, needs to be provided to all matching functions in this module. */
|
|
167
|
+
processedTree: ProcessedTree<TRouteLike, any, any>;
|
|
168
|
+
/** A lookup map of routes by their unique IDs. */
|
|
169
|
+
routesById: Record<string, TRouteLike>;
|
|
170
|
+
/** A lookup map of routes by their trimmed full paths. */
|
|
171
|
+
routesByPath: Record<string, TRouteLike>;
|
|
172
|
+
};
|
|
173
|
+
declare function findMatch<T extends RouteLike>(path: string, segmentTree: AnySegmentNode<T>, fuzzy?: boolean): {
|
|
174
|
+
route: T;
|
|
175
|
+
params: Record<string, string>;
|
|
176
|
+
} | null;
|
|
177
|
+
export {};
|