@tanstack/router-core 0.0.1-beta.9 → 1.20.3-alpha.1

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.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/Matches.cjs +13 -0
  4. package/dist/cjs/Matches.cjs.map +1 -0
  5. package/dist/cjs/Matches.d.cts +109 -0
  6. package/dist/cjs/RouterProvider.d.cts +26 -0
  7. package/dist/cjs/defer.cjs +25 -0
  8. package/dist/cjs/defer.cjs.map +1 -0
  9. package/dist/cjs/defer.d.cts +20 -0
  10. package/dist/cjs/fileRoute.d.cts +23 -0
  11. package/dist/cjs/history.d.cts +8 -0
  12. package/dist/cjs/index.cjs +80 -0
  13. package/dist/cjs/index.cjs.map +1 -0
  14. package/dist/cjs/index.d.cts +41 -0
  15. package/dist/cjs/link.cjs +5 -0
  16. package/dist/cjs/link.cjs.map +1 -0
  17. package/dist/cjs/link.d.cts +200 -0
  18. package/dist/cjs/location.d.cts +12 -0
  19. package/dist/cjs/manifest.d.cts +24 -0
  20. package/dist/cjs/not-found.cjs +13 -0
  21. package/dist/cjs/not-found.cjs.map +1 -0
  22. package/dist/cjs/not-found.d.cts +20 -0
  23. package/dist/cjs/path.cjs +412 -0
  24. package/dist/cjs/path.cjs.map +1 -0
  25. package/dist/cjs/path.d.cts +56 -0
  26. package/dist/cjs/qss.cjs +38 -0
  27. package/dist/cjs/qss.cjs.map +1 -0
  28. package/dist/cjs/qss.d.cts +22 -0
  29. package/dist/cjs/redirect.cjs +34 -0
  30. package/dist/cjs/redirect.cjs.map +1 -0
  31. package/dist/cjs/redirect.d.cts +38 -0
  32. package/dist/cjs/root.cjs +5 -0
  33. package/dist/cjs/root.cjs.map +1 -0
  34. package/dist/cjs/root.d.cts +2 -0
  35. package/dist/cjs/route.cjs +119 -0
  36. package/dist/cjs/route.cjs.map +1 -0
  37. package/dist/cjs/route.d.cts +422 -0
  38. package/dist/cjs/routeInfo.d.cts +54 -0
  39. package/dist/cjs/router.cjs +1800 -0
  40. package/dist/cjs/router.cjs.map +1 -0
  41. package/dist/cjs/router.d.cts +630 -0
  42. package/dist/cjs/scroll-restoration.cjs +196 -0
  43. package/dist/cjs/scroll-restoration.cjs.map +1 -0
  44. package/dist/cjs/scroll-restoration.d.cts +38 -0
  45. package/dist/cjs/searchMiddleware.cjs +42 -0
  46. package/dist/cjs/searchMiddleware.cjs.map +1 -0
  47. package/dist/cjs/searchMiddleware.d.cts +5 -0
  48. package/dist/cjs/searchParams.cjs +61 -0
  49. package/dist/cjs/searchParams.cjs.map +1 -0
  50. package/dist/cjs/searchParams.d.cts +7 -0
  51. package/dist/cjs/serializer.d.cts +22 -0
  52. package/dist/cjs/structuralSharing.d.cts +4 -0
  53. package/dist/cjs/typePrimitives.d.cts +65 -0
  54. package/dist/cjs/useLoaderData.d.cts +5 -0
  55. package/dist/cjs/useLoaderDeps.d.cts +5 -0
  56. package/dist/cjs/useNavigate.d.cts +3 -0
  57. package/dist/cjs/useParams.d.cts +5 -0
  58. package/dist/cjs/useRouteContext.d.cts +9 -0
  59. package/dist/cjs/useSearch.d.cts +5 -0
  60. package/dist/cjs/utils.cjs +160 -0
  61. package/dist/cjs/utils.cjs.map +1 -0
  62. package/dist/cjs/utils.d.cts +105 -0
  63. package/dist/cjs/validators.d.cts +51 -0
  64. package/dist/esm/Matches.d.ts +109 -0
  65. package/dist/esm/Matches.js +13 -0
  66. package/dist/esm/Matches.js.map +1 -0
  67. package/dist/esm/RouterProvider.d.ts +26 -0
  68. package/dist/esm/defer.d.ts +20 -0
  69. package/dist/esm/defer.js +25 -0
  70. package/dist/esm/defer.js.map +1 -0
  71. package/dist/esm/fileRoute.d.ts +23 -0
  72. package/dist/esm/history.d.ts +8 -0
  73. package/dist/esm/index.d.ts +41 -0
  74. package/dist/esm/index.js +80 -0
  75. package/dist/esm/index.js.map +1 -0
  76. package/dist/esm/link.d.ts +200 -0
  77. package/dist/esm/link.js +5 -0
  78. package/dist/esm/link.js.map +1 -0
  79. package/dist/esm/location.d.ts +12 -0
  80. package/dist/esm/manifest.d.ts +24 -0
  81. package/dist/esm/not-found.d.ts +20 -0
  82. package/dist/esm/not-found.js +13 -0
  83. package/dist/esm/not-found.js.map +1 -0
  84. package/dist/esm/path.d.ts +56 -0
  85. package/dist/esm/path.js +412 -0
  86. package/dist/esm/path.js.map +1 -0
  87. package/dist/esm/qss.d.ts +22 -0
  88. package/dist/esm/qss.js +38 -0
  89. package/dist/esm/qss.js.map +1 -0
  90. package/dist/esm/redirect.d.ts +38 -0
  91. package/dist/esm/redirect.js +34 -0
  92. package/dist/esm/redirect.js.map +1 -0
  93. package/dist/esm/root.d.ts +2 -0
  94. package/dist/esm/root.js +5 -0
  95. package/dist/esm/root.js.map +1 -0
  96. package/dist/esm/route.d.ts +422 -0
  97. package/dist/esm/route.js +119 -0
  98. package/dist/esm/route.js.map +1 -0
  99. package/dist/esm/routeInfo.d.ts +54 -0
  100. package/dist/esm/router.d.ts +630 -0
  101. package/dist/esm/router.js +1800 -0
  102. package/dist/esm/router.js.map +1 -0
  103. package/dist/esm/scroll-restoration.d.ts +38 -0
  104. package/dist/esm/scroll-restoration.js +196 -0
  105. package/dist/esm/scroll-restoration.js.map +1 -0
  106. package/dist/esm/searchMiddleware.d.ts +5 -0
  107. package/dist/esm/searchMiddleware.js +42 -0
  108. package/dist/esm/searchMiddleware.js.map +1 -0
  109. package/dist/esm/searchParams.d.ts +7 -0
  110. package/dist/esm/searchParams.js +61 -0
  111. package/dist/esm/searchParams.js.map +1 -0
  112. package/dist/esm/serializer.d.ts +22 -0
  113. package/dist/esm/structuralSharing.d.ts +4 -0
  114. package/dist/esm/typePrimitives.d.ts +65 -0
  115. package/dist/esm/useLoaderData.d.ts +5 -0
  116. package/dist/esm/useLoaderDeps.d.ts +5 -0
  117. package/dist/esm/useNavigate.d.ts +3 -0
  118. package/dist/esm/useParams.d.ts +5 -0
  119. package/dist/esm/useRouteContext.d.ts +9 -0
  120. package/dist/esm/useSearch.d.ts +5 -0
  121. package/dist/esm/utils.d.ts +105 -0
  122. package/dist/esm/utils.js +160 -0
  123. package/dist/esm/utils.js.map +1 -0
  124. package/dist/esm/validators.d.ts +51 -0
  125. package/package.json +36 -32
  126. package/src/Matches.ts +239 -0
  127. package/src/RouterProvider.ts +50 -0
  128. package/src/defer.ts +52 -0
  129. package/src/fileRoute.ts +140 -0
  130. package/src/history.ts +9 -0
  131. package/src/index.ts +421 -19
  132. package/src/link.ts +580 -286
  133. package/src/location.ts +13 -0
  134. package/src/manifest.ts +32 -0
  135. package/src/not-found.ts +29 -0
  136. package/src/path.ts +425 -49
  137. package/src/qss.ts +70 -41
  138. package/src/redirect.ts +100 -0
  139. package/src/root.ts +2 -0
  140. package/src/route.ts +1682 -218
  141. package/src/routeInfo.ts +224 -217
  142. package/src/router.ts +3100 -1073
  143. package/src/scroll-restoration.ts +340 -0
  144. package/src/searchMiddleware.ts +54 -0
  145. package/src/searchParams.ts +43 -20
  146. package/src/serializer.ts +32 -0
  147. package/src/structuralSharing.ts +7 -0
  148. package/src/typePrimitives.ts +181 -0
  149. package/src/useLoaderData.ts +20 -0
  150. package/src/useLoaderDeps.ts +13 -0
  151. package/src/useNavigate.ts +13 -0
  152. package/src/useParams.ts +20 -0
  153. package/src/useRouteContext.ts +39 -0
  154. package/src/useSearch.ts +20 -0
  155. package/src/utils.ts +369 -75
  156. package/src/validators.ts +121 -0
  157. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  158. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  159. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  160. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  161. package/build/cjs/node_modules/history/index.js +0 -815
  162. package/build/cjs/node_modules/history/index.js.map +0 -1
  163. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  164. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  165. package/build/cjs/packages/router-core/src/index.js +0 -58
  166. package/build/cjs/packages/router-core/src/index.js.map +0 -1
  167. package/build/cjs/packages/router-core/src/path.js +0 -222
  168. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  169. package/build/cjs/packages/router-core/src/qss.js +0 -71
  170. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  171. package/build/cjs/packages/router-core/src/route.js +0 -150
  172. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  173. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  174. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  175. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  176. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  177. package/build/cjs/packages/router-core/src/router.js +0 -822
  178. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  179. package/build/cjs/packages/router-core/src/searchParams.js +0 -70
  180. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  181. package/build/cjs/packages/router-core/src/utils.js +0 -125
  182. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  183. package/build/esm/index.js +0 -2481
  184. package/build/esm/index.js.map +0 -1
  185. package/build/stats-html.html +0 -4034
  186. package/build/stats-react.json +0 -493
  187. package/build/types/index.d.ts +0 -618
  188. package/build/umd/index.development.js +0 -2514
  189. package/build/umd/index.development.js.map +0 -1
  190. package/build/umd/index.production.js +0 -12
  191. package/build/umd/index.production.js.map +0 -1
  192. package/src/frameworks.ts +0 -12
  193. package/src/routeConfig.ts +0 -495
  194. package/src/routeMatch.ts +0 -374
@@ -0,0 +1,20 @@
1
+ import type { AllLoaderData, RouteById } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+ import type { Expand } from './utils'
4
+
5
+ export type ResolveUseLoaderData<
6
+ TRouter extends AnyRouter,
7
+ TFrom,
8
+ TStrict extends boolean,
9
+ > = TStrict extends false
10
+ ? AllLoaderData<TRouter['routeTree']>
11
+ : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['loaderData']>
12
+
13
+ export type UseLoaderDataResult<
14
+ TRouter extends AnyRouter,
15
+ TFrom,
16
+ TStrict extends boolean,
17
+ TSelected,
18
+ > = unknown extends TSelected
19
+ ? ResolveUseLoaderData<TRouter, TFrom, TStrict>
20
+ : TSelected
@@ -0,0 +1,13 @@
1
+ import type { RouteById } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+ import type { Expand } from './utils'
4
+
5
+ export type ResolveUseLoaderDeps<TRouter extends AnyRouter, TFrom> = Expand<
6
+ RouteById<TRouter['routeTree'], TFrom>['types']['loaderDeps']
7
+ >
8
+
9
+ export type UseLoaderDepsResult<
10
+ TRouter extends AnyRouter,
11
+ TFrom,
12
+ TSelected,
13
+ > = unknown extends TSelected ? ResolveUseLoaderDeps<TRouter, TFrom> : TSelected
@@ -0,0 +1,13 @@
1
+ import type { NavigateOptions } from './link'
2
+ import type { RegisteredRouter } from './router'
3
+
4
+ export type UseNavigateResult<TDefaultFrom extends string> = <
5
+ TRouter extends RegisteredRouter,
6
+ TTo extends string | undefined,
7
+ TFrom extends string = TDefaultFrom,
8
+ TMaskFrom extends string = TFrom,
9
+ TMaskTo extends string = '',
10
+ >({
11
+ from,
12
+ ...rest
13
+ }: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>
@@ -0,0 +1,20 @@
1
+ import type { AllParams, RouteById } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+ import type { Expand } from './utils'
4
+
5
+ export type ResolveUseParams<
6
+ TRouter extends AnyRouter,
7
+ TFrom,
8
+ TStrict extends boolean,
9
+ > = TStrict extends false
10
+ ? AllParams<TRouter['routeTree']>
11
+ : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allParams']>
12
+
13
+ export type UseParamsResult<
14
+ TRouter extends AnyRouter,
15
+ TFrom,
16
+ TStrict extends boolean,
17
+ TSelected,
18
+ > = unknown extends TSelected
19
+ ? ResolveUseParams<TRouter, TFrom, TStrict>
20
+ : TSelected
@@ -0,0 +1,39 @@
1
+ import type { AllContext, RouteById } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+ import type { Expand, StrictOrFrom } from './utils'
4
+
5
+ export interface UseRouteContextBaseOptions<
6
+ TRouter extends AnyRouter,
7
+ TFrom,
8
+ TStrict extends boolean,
9
+ TSelected,
10
+ > {
11
+ select?: (
12
+ search: ResolveUseRouteContext<TRouter, TFrom, TStrict>,
13
+ ) => TSelected
14
+ }
15
+
16
+ export type UseRouteContextOptions<
17
+ TRouter extends AnyRouter,
18
+ TFrom extends string | undefined,
19
+ TStrict extends boolean,
20
+ TSelected,
21
+ > = StrictOrFrom<TRouter, TFrom, TStrict> &
22
+ UseRouteContextBaseOptions<TRouter, TFrom, TStrict, TSelected>
23
+
24
+ export type ResolveUseRouteContext<
25
+ TRouter extends AnyRouter,
26
+ TFrom,
27
+ TStrict extends boolean,
28
+ > = TStrict extends false
29
+ ? AllContext<TRouter['routeTree']>
30
+ : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['allContext']>
31
+
32
+ export type UseRouteContextResult<
33
+ TRouter extends AnyRouter,
34
+ TFrom,
35
+ TStrict extends boolean,
36
+ TSelected,
37
+ > = unknown extends TSelected
38
+ ? ResolveUseRouteContext<TRouter, TFrom, TStrict>
39
+ : TSelected
@@ -0,0 +1,20 @@
1
+ import type { FullSearchSchema, RouteById } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+ import type { Expand } from './utils'
4
+
5
+ export type UseSearchResult<
6
+ TRouter extends AnyRouter,
7
+ TFrom,
8
+ TStrict extends boolean,
9
+ TSelected,
10
+ > = unknown extends TSelected
11
+ ? ResolveUseSearch<TRouter, TFrom, TStrict>
12
+ : TSelected
13
+
14
+ export type ResolveUseSearch<
15
+ TRouter extends AnyRouter,
16
+ TFrom,
17
+ TStrict extends boolean,
18
+ > = TStrict extends false
19
+ ? FullSearchSchema<TRouter['routeTree']>
20
+ : Expand<RouteById<TRouter['routeTree'], TFrom>['types']['fullSearchSchema']>
package/src/utils.ts CHANGED
@@ -1,50 +1,84 @@
1
+ import type { RouteIds } from './routeInfo'
2
+ import type { AnyRouter } from './router'
3
+
1
4
  export type NoInfer<T> = [T][T extends any ? 0 : never]
2
- export type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N
3
- export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false
4
- export type IsKnown<T, Y, N> = unknown extends T ? N : Y
5
- export type PickAsRequired<T, K extends keyof T> = Omit<T, K> &
6
- Required<Pick<T, K>>
7
- export type PickAsPartial<T, K extends keyof T> = Omit<T, K> &
8
- Partial<Pick<T, K>>
9
- export type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never
10
- export type PickExtra<T, K> = Expand<{
11
- [TKey in keyof K as string extends TKey
12
- ? never
13
- : TKey extends keyof T
14
- ? never
15
- : TKey]: K[TKey]
16
- }>
5
+ export type IsAny<TValue, TYesResult, TNoResult = TValue> = 1 extends 0 & TValue
6
+ ? TYesResult
7
+ : TNoResult
8
+
9
+ export type PickAsRequired<TValue, TKey extends keyof TValue> = Omit<
10
+ TValue,
11
+ TKey
12
+ > &
13
+ Required<Pick<TValue, TKey>>
14
+
17
15
  export type PickRequired<T> = {
18
16
  [K in keyof T as undefined extends T[K] ? never : K]: T[K]
19
17
  }
20
18
 
19
+ export type PickOptional<T> = {
20
+ [K in keyof T as undefined extends T[K] ? K : never]: T[K]
21
+ }
22
+
23
+ // from https://stackoverflow.com/a/76458160
24
+ export type WithoutEmpty<T> = T extends any ? ({} extends T ? never : T) : never
25
+
21
26
  export type Expand<T> = T extends object
22
27
  ? T extends infer O
23
- ? { [K in keyof O]: O[K] }
28
+ ? O extends Function
29
+ ? O
30
+ : { [K in keyof O]: O[K] }
24
31
  : never
25
32
  : T
26
33
 
27
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
28
- // k: infer I,
29
- // ) => any
30
- // ? I
31
- // : never
34
+ export type DeepPartial<T> = T extends object
35
+ ? {
36
+ [P in keyof T]?: DeepPartial<T[P]>
37
+ }
38
+ : T
32
39
 
33
- export type Values<O> = O[ValueKeys<O>]
34
- export type ValueKeys<O> = Extract<keyof O, PropertyKey>
40
+ export type MakeDifferenceOptional<TLeft, TRight> = keyof TLeft &
41
+ keyof TRight extends never
42
+ ? TRight
43
+ : Omit<TRight, keyof TLeft & keyof TRight> & {
44
+ [K in keyof TLeft & keyof TRight]?: TRight[K]
45
+ }
35
46
 
36
- export type DeepAwaited<T> = T extends Promise<infer A>
37
- ? DeepAwaited<A>
38
- : T extends Record<infer A, Promise<infer B>>
39
- ? { [K in A]: DeepAwaited<B> }
40
- : T
47
+ // from https://stackoverflow.com/a/53955431
48
+ // eslint-disable-next-line @typescript-eslint/naming-convention
49
+ export type IsUnion<T, U extends T = T> = (
50
+ T extends any ? (U extends T ? false : true) : never
51
+ ) extends false
52
+ ? false
53
+ : true
54
+
55
+ export type IsNonEmptyObject<T> = T extends object
56
+ ? keyof T extends never
57
+ ? false
58
+ : true
59
+ : false
41
60
 
42
- export type PathParamMask<TRoutePath extends string> =
43
- TRoutePath extends `${infer L}/:${infer C}/${infer R}`
44
- ? PathParamMask<`${L}/${string}/${R}`>
45
- : TRoutePath extends `${infer L}/:${infer C}`
46
- ? PathParamMask<`${L}/${string}`>
47
- : TRoutePath
61
+ export type Assign<TLeft, TRight> = TLeft extends any
62
+ ? TRight extends any
63
+ ? IsNonEmptyObject<TLeft> extends false
64
+ ? TRight
65
+ : IsNonEmptyObject<TRight> extends false
66
+ ? TLeft
67
+ : keyof TLeft & keyof TRight extends never
68
+ ? TLeft & TRight
69
+ : Omit<TLeft, keyof TRight> & TRight
70
+ : never
71
+ : never
72
+
73
+ export type IntersectAssign<TLeft, TRight> = TLeft extends any
74
+ ? TRight extends any
75
+ ? IsNonEmptyObject<TLeft> extends false
76
+ ? TRight
77
+ : IsNonEmptyObject<TRight> extends false
78
+ ? TLeft
79
+ : TRight & TLeft
80
+ : never
81
+ : never
48
82
 
49
83
  export type Timeout = ReturnType<typeof setTimeout>
50
84
 
@@ -52,50 +86,181 @@ export type Updater<TPrevious, TResult = TPrevious> =
52
86
  | TResult
53
87
  | ((prev?: TPrevious) => TResult)
54
88
 
55
- export type PickExtract<T, U> = {
56
- [K in keyof T as T[K] extends U ? K : never]: T[K]
89
+ export type NonNullableUpdater<TPrevious, TResult = TPrevious> =
90
+ | TResult
91
+ | ((prev: TPrevious) => TResult)
92
+
93
+ export type ExtractObjects<TUnion> = TUnion extends MergeAllPrimitive
94
+ ? never
95
+ : TUnion
96
+
97
+ export type PartialMergeAllObject<TUnion> =
98
+ ExtractObjects<TUnion> extends infer TObj
99
+ ? [TObj] extends [never]
100
+ ? never
101
+ : {
102
+ [TKey in TObj extends any ? keyof TObj : never]?: TObj extends any
103
+ ? TKey extends keyof TObj
104
+ ? TObj[TKey]
105
+ : never
106
+ : never
107
+ }
108
+ : never
109
+
110
+ export type MergeAllPrimitive =
111
+ | ReadonlyArray<any>
112
+ | number
113
+ | string
114
+ | bigint
115
+ | boolean
116
+ | symbol
117
+ | undefined
118
+ | null
119
+
120
+ export type ExtractPrimitives<TUnion> = TUnion extends MergeAllPrimitive
121
+ ? TUnion
122
+ : TUnion extends object
123
+ ? never
124
+ : TUnion
125
+
126
+ export type PartialMergeAll<TUnion> =
127
+ | ExtractPrimitives<TUnion>
128
+ | PartialMergeAllObject<TUnion>
129
+
130
+ export type Constrain<T, TConstraint, TDefault = TConstraint> =
131
+ | (T extends TConstraint ? T : never)
132
+ | TDefault
133
+
134
+ export type ConstrainLiteral<T, TConstraint, TDefault = TConstraint> =
135
+ | (T & TConstraint)
136
+ | TDefault
137
+
138
+ /**
139
+ * To be added to router types
140
+ */
141
+ export type UnionToIntersection<T> = (
142
+ T extends any ? (arg: T) => any : never
143
+ ) extends (arg: infer T) => any
144
+ ? T
145
+ : never
146
+
147
+ /**
148
+ * Merges everything in a union into one object.
149
+ * This mapped type is homomorphic which means it preserves stuff! :)
150
+ */
151
+ export type MergeAllObjects<
152
+ TUnion,
153
+ TIntersected = UnionToIntersection<ExtractObjects<TUnion>>,
154
+ > = [keyof TIntersected] extends [never]
155
+ ? never
156
+ : {
157
+ [TKey in keyof TIntersected]: TUnion extends any
158
+ ? TUnion[TKey & keyof TUnion]
159
+ : never
160
+ }
161
+
162
+ export type MergeAll<TUnion> =
163
+ | MergeAllObjects<TUnion>
164
+ | ExtractPrimitives<TUnion>
165
+
166
+ export type ValidateJSON<T> = ((...args: Array<any>) => any) extends T
167
+ ? unknown extends T
168
+ ? never
169
+ : 'Function is not serializable'
170
+ : { [K in keyof T]: ValidateJSON<T[K]> }
171
+
172
+ export type LooseReturnType<T> = T extends (
173
+ ...args: Array<any>
174
+ ) => infer TReturn
175
+ ? TReturn
176
+ : never
177
+
178
+ export type LooseAsyncReturnType<T> = T extends (
179
+ ...args: Array<any>
180
+ ) => infer TReturn
181
+ ? TReturn extends Promise<infer TReturn>
182
+ ? TReturn
183
+ : TReturn
184
+ : never
185
+
186
+ export function last<T>(arr: Array<T>) {
187
+ return arr[arr.length - 1]
57
188
  }
58
189
 
59
- export type PickExclude<T, U> = {
60
- [K in keyof T as T[K] extends U ? never : K]: T[K]
190
+ function isFunction(d: any): d is Function {
191
+ return typeof d === 'function'
192
+ }
193
+
194
+ export function functionalUpdate<TPrevious, TResult = TPrevious>(
195
+ updater: Updater<TPrevious, TResult> | NonNullableUpdater<TPrevious, TResult>,
196
+ previous: TPrevious,
197
+ ): TResult {
198
+ if (isFunction(updater)) {
199
+ return updater(previous)
200
+ }
201
+
202
+ return updater
203
+ }
204
+
205
+ export function pick<TValue, TKey extends keyof TValue>(
206
+ parent: TValue,
207
+ keys: Array<TKey>,
208
+ ): Pick<TValue, TKey> {
209
+ return keys.reduce((obj: any, key: TKey) => {
210
+ obj[key] = parent[key]
211
+ return obj
212
+ }, {} as any)
61
213
  }
62
214
 
63
215
  /**
64
- * This function returns `a` if `b` is deeply equal.
216
+ * This function returns `prev` if `_next` is deeply equal.
65
217
  * If not, it will replace any deeply equal children of `b` with those of `a`.
66
- * This can be used for structural sharing between JSON values for example.
218
+ * This can be used for structural sharing between immutable JSON values for example.
219
+ * Do not use this with signals
67
220
  */
68
- export function replaceEqualDeep(prev: any, next: any) {
69
- if (prev === next) {
221
+ export function replaceEqualDeep<T>(prev: any, _next: T): T {
222
+ if (prev === _next) {
70
223
  return prev
71
224
  }
72
225
 
73
- const array = Array.isArray(prev) && Array.isArray(next)
226
+ const next = _next as any
227
+
228
+ const array = isPlainArray(prev) && isPlainArray(next)
74
229
 
75
230
  if (array || (isPlainObject(prev) && isPlainObject(next))) {
76
- const aSize = array ? prev.length : Object.keys(prev).length
77
- const bItems = array ? next : Object.keys(next)
78
- const bSize = bItems.length
231
+ const prevItems = array ? prev : Object.keys(prev)
232
+ const prevSize = prevItems.length
233
+ const nextItems = array ? next : Object.keys(next)
234
+ const nextSize = nextItems.length
79
235
  const copy: any = array ? [] : {}
80
236
 
81
237
  let equalItems = 0
82
238
 
83
- for (let i = 0; i < bSize; i++) {
84
- const key = array ? i : bItems[i]
85
- copy[key] = replaceEqualDeep(prev[key], next[key])
86
- if (copy[key] === prev[key]) {
239
+ for (let i = 0; i < nextSize; i++) {
240
+ const key = array ? i : (nextItems[i] as any)
241
+ if (
242
+ ((!array && prevItems.includes(key)) || array) &&
243
+ prev[key] === undefined &&
244
+ next[key] === undefined
245
+ ) {
246
+ copy[key] = undefined
87
247
  equalItems++
248
+ } else {
249
+ copy[key] = replaceEqualDeep(prev[key], next[key])
250
+ if (copy[key] === prev[key] && prev[key] !== undefined) {
251
+ equalItems++
252
+ }
88
253
  }
89
254
  }
90
255
 
91
- return aSize === bSize && equalItems === aSize ? prev : copy
256
+ return prevSize === nextSize && equalItems === prevSize ? prev : copy
92
257
  }
93
258
 
94
259
  return next
95
260
  }
96
261
 
97
262
  // Copied from: https://github.com/jonschlinkert/is-plain-object
98
- function isPlainObject(o: any) {
263
+ export function isPlainObject(o: any) {
99
264
  if (!hasObjectPrototype(o)) {
100
265
  return false
101
266
  }
@@ -125,40 +290,169 @@ function hasObjectPrototype(o: any) {
125
290
  return Object.prototype.toString.call(o) === '[object Object]'
126
291
  }
127
292
 
128
- export function last<T>(arr: T[]) {
129
- return arr[arr.length - 1]
293
+ export function isPlainArray(value: unknown): value is Array<unknown> {
294
+ return Array.isArray(value) && value.length === Object.keys(value).length
130
295
  }
131
296
 
132
- export function warning(cond: any, message: string): cond is true {
133
- if (cond) {
134
- if (typeof console !== 'undefined') console.warn(message)
297
+ function getObjectKeys(obj: any, ignoreUndefined: boolean) {
298
+ let keys = Object.keys(obj)
299
+ if (ignoreUndefined) {
300
+ keys = keys.filter((key) => obj[key] !== undefined)
301
+ }
302
+ return keys
303
+ }
135
304
 
136
- try {
137
- throw new Error(message)
138
- } catch {}
305
+ export function deepEqual(
306
+ a: any,
307
+ b: any,
308
+ opts?: { partial?: boolean; ignoreUndefined?: boolean },
309
+ ): boolean {
310
+ if (a === b) {
311
+ return true
139
312
  }
140
313
 
141
- return true
314
+ if (typeof a !== typeof b) {
315
+ return false
316
+ }
317
+
318
+ if (isPlainObject(a) && isPlainObject(b)) {
319
+ const ignoreUndefined = opts?.ignoreUndefined ?? true
320
+ const aKeys = getObjectKeys(a, ignoreUndefined)
321
+ const bKeys = getObjectKeys(b, ignoreUndefined)
322
+
323
+ if (!opts?.partial && aKeys.length !== bKeys.length) {
324
+ return false
325
+ }
326
+
327
+ return bKeys.every((key) => deepEqual(a[key], b[key], opts))
328
+ }
329
+
330
+ if (Array.isArray(a) && Array.isArray(b)) {
331
+ if (a.length !== b.length) {
332
+ return false
333
+ }
334
+ return !a.some((item, index) => !deepEqual(item, b[index], opts))
335
+ }
336
+
337
+ return false
142
338
  }
143
339
 
144
- function isFunction(d: any): d is Function {
145
- return typeof d === 'function'
340
+ export type StringLiteral<T> = T extends string
341
+ ? string extends T
342
+ ? string
343
+ : T
344
+ : never
345
+
346
+ export type ThrowOrOptional<T, TThrow extends boolean> = TThrow extends true
347
+ ? T
348
+ : T | undefined
349
+
350
+ export type StrictOrFrom<
351
+ TRouter extends AnyRouter,
352
+ TFrom,
353
+ TStrict extends boolean = true,
354
+ > = TStrict extends false
355
+ ? {
356
+ from?: never
357
+ strict: TStrict
358
+ }
359
+ : {
360
+ from: ConstrainLiteral<TFrom, RouteIds<TRouter['routeTree']>>
361
+ strict?: TStrict
362
+ }
363
+
364
+ export type ThrowConstraint<
365
+ TStrict extends boolean,
366
+ TThrow extends boolean,
367
+ > = TStrict extends false ? (TThrow extends true ? never : TThrow) : TThrow
368
+
369
+ export type ControlledPromise<T> = Promise<T> & {
370
+ resolve: (value: T) => void
371
+ reject: (value: any) => void
372
+ status: 'pending' | 'resolved' | 'rejected'
373
+ value?: T
146
374
  }
147
375
 
148
- export function functionalUpdate<TResult>(
149
- updater: Updater<TResult>,
150
- previous: TResult,
151
- ) {
152
- if (isFunction(updater)) {
153
- return updater(previous as TResult)
376
+ export function createControlledPromise<T>(onResolve?: (value: T) => void) {
377
+ let resolveLoadPromise!: (value: T) => void
378
+ let rejectLoadPromise!: (value: any) => void
379
+
380
+ const controlledPromise = new Promise<T>((resolve, reject) => {
381
+ resolveLoadPromise = resolve
382
+ rejectLoadPromise = reject
383
+ }) as ControlledPromise<T>
384
+
385
+ controlledPromise.status = 'pending'
386
+
387
+ controlledPromise.resolve = (value: T) => {
388
+ controlledPromise.status = 'resolved'
389
+ controlledPromise.value = value
390
+ resolveLoadPromise(value)
391
+ onResolve?.(value)
154
392
  }
155
393
 
156
- return updater
394
+ controlledPromise.reject = (e) => {
395
+ controlledPromise.status = 'rejected'
396
+ rejectLoadPromise(e)
397
+ }
398
+
399
+ return controlledPromise
157
400
  }
158
401
 
159
- export function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {
160
- return keys.reduce((obj: any, key: K) => {
161
- obj[key] = parent[key]
162
- return obj
163
- }, {} as any)
402
+ /**
403
+ *
404
+ * @deprecated use `jsesc` instead
405
+ */
406
+ export function escapeJSON(jsonString: string) {
407
+ return jsonString
408
+ .replace(/\\/g, '\\\\') // Escape backslashes
409
+ .replace(/'/g, "\\'") // Escape single quotes
410
+ .replace(/"/g, '\\"') // Escape double quotes
411
+ }
412
+
413
+ export function shallow<T>(objA: T, objB: T) {
414
+ if (Object.is(objA, objB)) {
415
+ return true
416
+ }
417
+
418
+ if (
419
+ typeof objA !== 'object' ||
420
+ objA === null ||
421
+ typeof objB !== 'object' ||
422
+ objB === null
423
+ ) {
424
+ return false
425
+ }
426
+
427
+ const keysA = Object.keys(objA)
428
+ if (keysA.length !== Object.keys(objB).length) {
429
+ return false
430
+ }
431
+
432
+ for (const item of keysA) {
433
+ if (
434
+ !Object.prototype.hasOwnProperty.call(objB, item) ||
435
+ !Object.is(objA[item as keyof T], objB[item as keyof T])
436
+ ) {
437
+ return false
438
+ }
439
+ }
440
+ return true
441
+ }
442
+
443
+ /**
444
+ * Checks if a string contains URI-encoded special characters (e.g., %3F, %20).
445
+ *
446
+ * @param {string} inputString The string to check.
447
+ * @returns {boolean} True if the string contains URI-encoded characters, false otherwise.
448
+ * @example
449
+ * ```typescript
450
+ * const str1 = "foo%3Fbar";
451
+ * const hasEncodedChars = hasUriEncodedChars(str1); // returns true
452
+ * ```
453
+ */
454
+ export function hasUriEncodedChars(inputString: string): boolean {
455
+ // This regex looks for a percent sign followed by two hexadecimal digits
456
+ const pattern = /%[0-9A-Fa-f]{2}/
457
+ return pattern.test(inputString)
164
458
  }