-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.ts
More file actions
59 lines (55 loc) · 1.73 KB
/
Types.ts
File metadata and controls
59 lines (55 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Router context containing the tree structure and static route cache.
* @template T - Type of data associated with routes
*/
export interface RouterContext<T = unknown> {
/** Root node of the router tree */
root: RouterNode<T>
/** Static route cache for fast lookups */
static: Record<string, RouterNode<T> | undefined>
}
/**
* Result of a successful route match.
* @template T - Type of data associated with the matched route
*/
export interface RouterMatchedRoute<T = unknown> {
/** Data associated with the matched route */
data: T
/** Extracted route parameters */
params: Record<string, string> | undefined
}
/**
* Method-specific data stored in router nodes.
* @template T - Type of data associated with routes
*/
export interface RouterMethodData<T = unknown> {
/** Data associated with the route */
data: T
/** Parameter mapping for route segments */
paramsMap: RouterParamsMap | undefined
/** Regular expressions for parameter validation */
paramsRegexp: RegExp[]
}
/**
* Node in the router tree structure.
* @template T - Type of data associated with routes
*/
export interface RouterNode<T = unknown> {
/** Node key/segment value */
key: string
/** Static child nodes */
static?: Record<string, RouterNode<T>>
/** Parameter child node */
param?: RouterNode<T>
/** Wildcard child node */
wildcard?: RouterNode<T>
/** Whether this node has regex parameter validation */
hasRegexParam?: boolean
/** HTTP method handlers */
methods?: Record<string, RouterMethodData<T>[] | undefined>
}
/**
* Parameter mapping array for route segments.
* Each tuple contains [index, name/regex, optional]
*/
export type RouterParamsMap = Array<[Index: number, name: string | RegExp, optional: boolean]>