@@ -11,13 +11,17 @@ import type {
11
11
StructuralSharingOption ,
12
12
ValidateSelected ,
13
13
} from './structuralSharing'
14
- import type { AnyRoute , ReactNode , StaticDataRouteOption } from './route'
14
+ import type { AnyRoute , ReactNode } from './route'
15
+ import type { ControlledPromise ,
16
+ DeepPartial ,
17
+ NoInfer ,
18
+ ResolveRelativePath ,
19
+ StaticDataRouteOption } from '@tanstack/router-core'
15
20
import type { AnyRouter , RegisteredRouter , RouterState } from './router'
16
21
import type {
17
22
MakeOptionalPathParams ,
18
23
MakeOptionalSearchParams ,
19
24
MaskOptions ,
20
- ResolveRelativePath ,
21
25
ResolveRoute ,
22
26
ToSubOptionsProps ,
23
27
} from './link'
@@ -31,105 +35,6 @@ import type {
31
35
RouteByPath ,
32
36
RouteIds ,
33
37
} from './routeInfo'
34
- import type {
35
- Constrain ,
36
- ControlledPromise ,
37
- DeepPartial ,
38
- NoInfer ,
39
- } from './utils'
40
-
41
- export type AnyMatchAndValue = { match : any ; value : any }
42
-
43
- export type FindValueByIndex <
44
- TKey ,
45
- TValue extends ReadonlyArray < any > ,
46
- > = TKey extends `${infer TIndex extends number } ` ? TValue [ TIndex ] : never
47
-
48
- export type FindValueByKey < TKey , TValue > =
49
- TValue extends ReadonlyArray < any >
50
- ? FindValueByIndex < TKey , TValue >
51
- : TValue [ TKey & keyof TValue ]
52
-
53
- export type CreateMatchAndValue < TMatch , TValue > = TValue extends any
54
- ? {
55
- match : TMatch
56
- value : TValue
57
- }
58
- : never
59
-
60
- export type NextMatchAndValue <
61
- TKey ,
62
- TMatchAndValue extends AnyMatchAndValue ,
63
- > = TMatchAndValue extends any
64
- ? CreateMatchAndValue <
65
- TMatchAndValue [ 'match' ] ,
66
- FindValueByKey < TKey , TMatchAndValue [ 'value' ] >
67
- >
68
- : never
69
-
70
- export type IsMatchKeyOf < TValue > =
71
- TValue extends ReadonlyArray < any >
72
- ? number extends TValue [ 'length' ]
73
- ? `${number } `
74
- : keyof TValue & `${number } `
75
- : TValue extends object
76
- ? keyof TValue & string
77
- : never
78
-
79
- export type IsMatchPath <
80
- TParentPath extends string ,
81
- TMatchAndValue extends AnyMatchAndValue ,
82
- > = `${TParentPath } ${IsMatchKeyOf < TMatchAndValue [ 'value' ] > } `
83
-
84
- export type IsMatchResult <
85
- TKey ,
86
- TMatchAndValue extends AnyMatchAndValue ,
87
- > = TMatchAndValue extends any
88
- ? TKey extends keyof TMatchAndValue [ 'value' ]
89
- ? TMatchAndValue [ 'match' ]
90
- : never
91
- : never
92
-
93
- export type IsMatchParse <
94
- TPath ,
95
- TMatchAndValue extends AnyMatchAndValue ,
96
- TParentPath extends string = '' ,
97
- > = TPath extends `${string } .${string } `
98
- ? TPath extends `${infer TFirst } .${infer TRest } `
99
- ? IsMatchParse <
100
- TRest ,
101
- NextMatchAndValue < TFirst , TMatchAndValue > ,
102
- `${TParentPath } ${TFirst } .`
103
- >
104
- : never
105
- : {
106
- path : IsMatchPath < TParentPath , TMatchAndValue >
107
- result : IsMatchResult < TPath , TMatchAndValue >
108
- }
109
-
110
- export type IsMatch < TMatch , TPath > = IsMatchParse <
111
- TPath ,
112
- TMatch extends any ? { match : TMatch ; value : TMatch } : never
113
- >
114
-
115
- /**
116
- * Narrows matches based on a path
117
- * @experimental
118
- */
119
- export const isMatch = < TMatch , TPath extends string > (
120
- match : TMatch ,
121
- path : Constrain < TPath , IsMatch < TMatch , TPath > [ 'path' ] > ,
122
- ) : match is IsMatch < TMatch , TPath > [ 'result' ] => {
123
- const parts = ( path as string ) . split ( '.' )
124
- let part
125
- let value : any = match
126
-
127
- while ( ( part = parts . shift ( ) ) != null && value != null ) {
128
- value = value [ part ]
129
- }
130
-
131
- return value != null
132
- }
133
38
134
39
export type MakeRouteMatchFromRoute < TRoute extends AnyRoute > = RouteMatch <
135
40
TRoute [ 'types' ] [ 'id' ] ,
0 commit comments