@tanstack/router-core 0.0.1-beta.9 → 1.97.21

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 (140) 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 +28 -0
  6. package/dist/cjs/RouterProvider.d.cts +18 -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/index.cjs +50 -0
  11. package/dist/cjs/index.cjs.map +1 -0
  12. package/dist/cjs/index.d.cts +25 -0
  13. package/dist/cjs/link.cjs +5 -0
  14. package/dist/cjs/link.cjs.map +1 -0
  15. package/dist/cjs/link.d.cts +51 -0
  16. package/dist/cjs/location.d.cts +12 -0
  17. package/dist/cjs/manifest.d.cts +24 -0
  18. package/dist/cjs/path.cjs +289 -0
  19. package/dist/cjs/path.cjs.map +1 -0
  20. package/dist/cjs/path.d.cts +34 -0
  21. package/dist/cjs/qss.cjs +51 -0
  22. package/dist/cjs/qss.cjs.map +1 -0
  23. package/dist/cjs/qss.d.cts +27 -0
  24. package/dist/cjs/root.cjs +5 -0
  25. package/dist/cjs/root.cjs.map +1 -0
  26. package/dist/cjs/root.d.cts +2 -0
  27. package/dist/cjs/route.d.cts +148 -0
  28. package/dist/cjs/router.cjs +19 -0
  29. package/dist/cjs/router.cjs.map +1 -0
  30. package/dist/cjs/router.d.cts +31 -0
  31. package/dist/cjs/searchMiddleware.cjs +42 -0
  32. package/dist/cjs/searchMiddleware.cjs.map +1 -0
  33. package/dist/cjs/searchMiddleware.d.cts +5 -0
  34. package/dist/cjs/searchParams.cjs +61 -0
  35. package/dist/cjs/searchParams.cjs.map +1 -0
  36. package/dist/cjs/searchParams.d.cts +7 -0
  37. package/dist/cjs/serializer.d.cts +15 -0
  38. package/dist/cjs/structuralSharing.d.cts +4 -0
  39. package/dist/cjs/utils.cjs +155 -0
  40. package/dist/cjs/utils.cjs.map +1 -0
  41. package/dist/cjs/utils.d.cts +81 -0
  42. package/dist/cjs/validators.d.cts +51 -0
  43. package/dist/esm/Matches.d.ts +28 -0
  44. package/dist/esm/Matches.js +13 -0
  45. package/dist/esm/Matches.js.map +1 -0
  46. package/dist/esm/RouterProvider.d.ts +18 -0
  47. package/dist/esm/defer.d.ts +20 -0
  48. package/dist/esm/defer.js +25 -0
  49. package/dist/esm/defer.js.map +1 -0
  50. package/dist/esm/index.d.ts +25 -0
  51. package/dist/esm/index.js +50 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/link.d.ts +51 -0
  54. package/dist/esm/link.js +5 -0
  55. package/dist/esm/link.js.map +1 -0
  56. package/dist/esm/location.d.ts +12 -0
  57. package/dist/esm/manifest.d.ts +24 -0
  58. package/dist/esm/path.d.ts +34 -0
  59. package/dist/esm/path.js +289 -0
  60. package/dist/esm/path.js.map +1 -0
  61. package/dist/esm/qss.d.ts +27 -0
  62. package/dist/esm/qss.js +51 -0
  63. package/dist/esm/qss.js.map +1 -0
  64. package/dist/esm/root.d.ts +2 -0
  65. package/dist/esm/root.js +5 -0
  66. package/dist/esm/root.js.map +1 -0
  67. package/dist/esm/route.d.ts +148 -0
  68. package/dist/esm/router.d.ts +31 -0
  69. package/dist/esm/router.js +19 -0
  70. package/dist/esm/router.js.map +1 -0
  71. package/dist/esm/searchMiddleware.d.ts +5 -0
  72. package/dist/esm/searchMiddleware.js +42 -0
  73. package/dist/esm/searchMiddleware.js.map +1 -0
  74. package/dist/esm/searchParams.d.ts +7 -0
  75. package/dist/esm/searchParams.js +61 -0
  76. package/dist/esm/searchParams.js.map +1 -0
  77. package/dist/esm/serializer.d.ts +15 -0
  78. package/dist/esm/structuralSharing.d.ts +4 -0
  79. package/dist/esm/utils.d.ts +81 -0
  80. package/dist/esm/utils.js +155 -0
  81. package/dist/esm/utils.js.map +1 -0
  82. package/dist/esm/validators.d.ts +51 -0
  83. package/package.json +35 -32
  84. package/src/Matches.ts +94 -0
  85. package/src/RouterProvider.ts +20 -0
  86. package/src/defer.ts +52 -0
  87. package/src/index.ts +206 -19
  88. package/src/link.ts +122 -300
  89. package/src/location.ts +13 -0
  90. package/src/manifest.ts +32 -0
  91. package/src/path.ts +238 -47
  92. package/src/qss.ts +56 -19
  93. package/src/root.ts +2 -0
  94. package/src/route.ts +296 -223
  95. package/src/router.ts +34 -1281
  96. package/src/searchMiddleware.ts +54 -0
  97. package/src/searchParams.ts +43 -20
  98. package/src/serializer.ts +24 -0
  99. package/src/structuralSharing.ts +7 -0
  100. package/src/utils.ts +314 -75
  101. package/src/validators.ts +121 -0
  102. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  103. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  104. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  105. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  106. package/build/cjs/node_modules/history/index.js +0 -815
  107. package/build/cjs/node_modules/history/index.js.map +0 -1
  108. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  109. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  110. package/build/cjs/packages/router-core/src/index.js +0 -58
  111. package/build/cjs/packages/router-core/src/index.js.map +0 -1
  112. package/build/cjs/packages/router-core/src/path.js +0 -222
  113. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  114. package/build/cjs/packages/router-core/src/qss.js +0 -71
  115. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  116. package/build/cjs/packages/router-core/src/route.js +0 -150
  117. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  118. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  119. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  120. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  121. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  122. package/build/cjs/packages/router-core/src/router.js +0 -822
  123. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  124. package/build/cjs/packages/router-core/src/searchParams.js +0 -70
  125. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  126. package/build/cjs/packages/router-core/src/utils.js +0 -125
  127. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  128. package/build/esm/index.js +0 -2481
  129. package/build/esm/index.js.map +0 -1
  130. package/build/stats-html.html +0 -4034
  131. package/build/stats-react.json +0 -493
  132. package/build/types/index.d.ts +0 -618
  133. package/build/umd/index.development.js +0 -2514
  134. package/build/umd/index.development.js.map +0 -1
  135. package/build/umd/index.production.js +0 -12
  136. package/build/umd/index.production.js.map +0 -1
  137. package/src/frameworks.ts +0 -12
  138. package/src/routeConfig.ts +0 -495
  139. package/src/routeInfo.ts +0 -228
  140. package/src/routeMatch.ts +0 -374
package/src/Matches.ts ADDED
@@ -0,0 +1,94 @@
1
+ import type { Constrain } from './utils'
2
+
3
+ export type AnyMatchAndValue = { match: any; value: any }
4
+
5
+ export type FindValueByIndex<
6
+ TKey,
7
+ TValue extends ReadonlyArray<any>,
8
+ > = TKey extends `${infer TIndex extends number}` ? TValue[TIndex] : never
9
+
10
+ export type FindValueByKey<TKey, TValue> =
11
+ TValue extends ReadonlyArray<any>
12
+ ? FindValueByIndex<TKey, TValue>
13
+ : TValue[TKey & keyof TValue]
14
+
15
+ export type CreateMatchAndValue<TMatch, TValue> = TValue extends any
16
+ ? {
17
+ match: TMatch
18
+ value: TValue
19
+ }
20
+ : never
21
+
22
+ export type NextMatchAndValue<
23
+ TKey,
24
+ TMatchAndValue extends AnyMatchAndValue,
25
+ > = TMatchAndValue extends any
26
+ ? CreateMatchAndValue<
27
+ TMatchAndValue['match'],
28
+ FindValueByKey<TKey, TMatchAndValue['value']>
29
+ >
30
+ : never
31
+
32
+ export type IsMatchKeyOf<TValue> =
33
+ TValue extends ReadonlyArray<any>
34
+ ? number extends TValue['length']
35
+ ? `${number}`
36
+ : keyof TValue & `${number}`
37
+ : TValue extends object
38
+ ? keyof TValue & string
39
+ : never
40
+
41
+ export type IsMatchPath<
42
+ TParentPath extends string,
43
+ TMatchAndValue extends AnyMatchAndValue,
44
+ > = `${TParentPath}${IsMatchKeyOf<TMatchAndValue['value']>}`
45
+
46
+ export type IsMatchResult<
47
+ TKey,
48
+ TMatchAndValue extends AnyMatchAndValue,
49
+ > = TMatchAndValue extends any
50
+ ? TKey extends keyof TMatchAndValue['value']
51
+ ? TMatchAndValue['match']
52
+ : never
53
+ : never
54
+
55
+ export type IsMatchParse<
56
+ TPath,
57
+ TMatchAndValue extends AnyMatchAndValue,
58
+ TParentPath extends string = '',
59
+ > = TPath extends `${string}.${string}`
60
+ ? TPath extends `${infer TFirst}.${infer TRest}`
61
+ ? IsMatchParse<
62
+ TRest,
63
+ NextMatchAndValue<TFirst, TMatchAndValue>,
64
+ `${TParentPath}${TFirst}.`
65
+ >
66
+ : never
67
+ : {
68
+ path: IsMatchPath<TParentPath, TMatchAndValue>
69
+ result: IsMatchResult<TPath, TMatchAndValue>
70
+ }
71
+
72
+ export type IsMatch<TMatch, TPath> = IsMatchParse<
73
+ TPath,
74
+ TMatch extends any ? { match: TMatch; value: TMatch } : never
75
+ >
76
+
77
+ /**
78
+ * Narrows matches based on a path
79
+ * @experimental
80
+ */
81
+ export const isMatch = <TMatch, TPath extends string>(
82
+ match: TMatch,
83
+ path: Constrain<TPath, IsMatch<TMatch, TPath>['path']>,
84
+ ): match is IsMatch<TMatch, TPath>['result'] => {
85
+ const parts = (path as string).split('.')
86
+ let part
87
+ let value: any = match
88
+
89
+ while ((part = parts.shift()) != null && value != null) {
90
+ value = value[part]
91
+ }
92
+
93
+ return value != null
94
+ }
@@ -0,0 +1,20 @@
1
+ import type { ViewTransitionOptions } from './router'
2
+
3
+ export interface MatchLocation {
4
+ to?: string | number | null
5
+ fuzzy?: boolean
6
+ caseSensitive?: boolean
7
+ from?: string
8
+ }
9
+
10
+ export interface CommitLocationOptions {
11
+ replace?: boolean
12
+ resetScroll?: boolean
13
+ hashScrollIntoView?: boolean | ScrollIntoViewOptions
14
+ viewTransition?: boolean | ViewTransitionOptions
15
+ /**
16
+ * @deprecated All navigations use React transitions under the hood now
17
+ **/
18
+ startTransition?: boolean
19
+ ignoreBlocker?: boolean
20
+ }
package/src/defer.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { defaultSerializeError } from './router'
2
+
3
+ export const TSR_DEFERRED_PROMISE = Symbol.for('TSR_DEFERRED_PROMISE')
4
+
5
+ export type DeferredPromiseState<T> =
6
+ | {
7
+ status: 'pending'
8
+ data?: T
9
+ error?: unknown
10
+ }
11
+ | {
12
+ status: 'success'
13
+ data: T
14
+ }
15
+ | {
16
+ status: 'error'
17
+ data?: T
18
+ error: unknown
19
+ }
20
+
21
+ export type DeferredPromise<T> = Promise<T> & {
22
+ [TSR_DEFERRED_PROMISE]: DeferredPromiseState<T>
23
+ }
24
+
25
+ export function defer<T>(
26
+ _promise: Promise<T>,
27
+ options?: {
28
+ serializeError?: typeof defaultSerializeError
29
+ },
30
+ ) {
31
+ const promise = _promise as DeferredPromise<T>
32
+ // this is already deferred promise
33
+ if ((promise as any)[TSR_DEFERRED_PROMISE]) {
34
+ return promise
35
+ }
36
+ promise[TSR_DEFERRED_PROMISE] = { status: 'pending' }
37
+
38
+ promise
39
+ .then((data) => {
40
+ promise[TSR_DEFERRED_PROMISE].status = 'success'
41
+ promise[TSR_DEFERRED_PROMISE].data = data
42
+ })
43
+ .catch((error) => {
44
+ promise[TSR_DEFERRED_PROMISE].status = 'error'
45
+ ;(promise[TSR_DEFERRED_PROMISE] as any).error = {
46
+ data: (options?.serializeError ?? defaultSerializeError)(error),
47
+ __isServerError: true,
48
+ }
49
+ })
50
+
51
+ return promise
52
+ }
package/src/index.ts CHANGED
@@ -1,20 +1,207 @@
1
+ export { TSR_DEFERRED_PROMISE, defer } from './defer'
2
+ export type { DeferredPromiseState, DeferredPromise } from './defer'
3
+ export { preloadWarning } from './link'
4
+ export type {
5
+ IsRequiredParams,
6
+ ParsePathParams,
7
+ AddTrailingSlash,
8
+ RemoveTrailingSlashes,
9
+ AddLeadingSlash,
10
+ RemoveLeadingSlashes,
11
+ ActiveOptions,
12
+ LinkOptionsProps,
13
+ ResolveCurrentPath,
14
+ ResolveParentPath,
15
+ ResolveRelativePath,
16
+ LinkCurrentTargetElement,
17
+ } from './link'
18
+
19
+ export type {
20
+ StartSerializer,
21
+ Serializable,
22
+ SerializerParse,
23
+ SerializerParseBy,
24
+ SerializerStringify,
25
+ SerializerStringifyBy,
26
+ } from './serializer'
27
+
28
+ export type { ParsedLocation } from './location'
29
+ export type { Manifest, RouterManagedTag } from './manifest'
30
+ export { isMatch } from './Matches'
31
+ export type {
32
+ AnyMatchAndValue,
33
+ FindValueByIndex,
34
+ FindValueByKey,
35
+ CreateMatchAndValue,
36
+ NextMatchAndValue,
37
+ IsMatchKeyOf,
38
+ IsMatchPath,
39
+ IsMatchResult,
40
+ IsMatchParse,
41
+ IsMatch,
42
+ } from './Matches'
43
+ export {
44
+ joinPaths,
45
+ cleanPath,
46
+ trimPathLeft,
47
+ trimPathRight,
48
+ trimPath,
49
+ removeTrailingSlash,
50
+ exactPathTest,
51
+ resolvePath,
52
+ parsePathname,
53
+ interpolatePath,
54
+ matchPathname,
55
+ removeBasepath,
56
+ matchByPath,
57
+ } from './path'
58
+ export type { Segment } from './path'
59
+ export { encode, decode } from './qss'
60
+ export { rootRouteId } from './root'
61
+ export type { RootRouteId } from './root'
62
+
63
+ export type {
64
+ AnyPathParams,
65
+ SearchSchemaInput,
66
+ AnyContext,
67
+ RouteContext,
68
+ PreloadableObj,
69
+ RoutePathOptions,
70
+ StaticDataRouteOption,
71
+ RoutePathOptionsIntersection,
72
+ SearchFilter,
73
+ SearchMiddlewareContext,
74
+ SearchMiddleware,
75
+ ResolveId,
76
+ InferFullSearchSchema,
77
+ InferFullSearchSchemaInput,
78
+ InferAllParams,
79
+ InferAllContext,
80
+ MetaDescriptor,
81
+ RouteLinkEntry,
82
+ SearchValidator,
83
+ AnySearchValidator,
84
+ DefaultSearchValidator,
85
+ ErrorRouteProps,
86
+ ErrorComponentProps,
87
+ NotFoundRouteProps,
88
+ ParseSplatParams,
89
+ SplatParams,
90
+ ResolveParams,
91
+ ParseParamsFn,
92
+ StringifyParamsFn,
93
+ ParamsOptions,
94
+ UpdatableStaticRouteOption,
95
+ LooseReturnType,
96
+ LooseAsyncReturnType,
97
+ ContextReturnType,
98
+ ContextAsyncReturnType,
99
+ ResolveRouteContext,
100
+ ResolveLoaderData,
101
+ RoutePrefix,
102
+ TrimPath,
103
+ TrimPathLeft,
104
+ TrimPathRight,
105
+ ResolveSearchSchemaFnInput,
106
+ ResolveSearchSchemaInput,
107
+ ResolveSearchSchemaFn,
108
+ ResolveSearchSchema,
109
+ } from './route'
110
+
111
+ export { defaultSerializeError } from './router'
112
+ export type {
113
+ ViewTransitionOptions,
114
+ ExtractedBaseEntry,
115
+ ExtractedStream,
116
+ ExtractedPromise,
117
+ ExtractedEntry,
118
+ StreamState,
119
+ TrailingSlashOption,
120
+ } from './router'
121
+
122
+ export type { MatchLocation, CommitLocationOptions } from './RouterProvider'
123
+
124
+ export { retainSearchParams, stripSearchParams } from './searchMiddleware'
125
+
126
+ export {
127
+ defaultParseSearch,
128
+ defaultStringifySearch,
129
+ parseSearchWith,
130
+ stringifySearchWith,
131
+ } from './searchParams'
132
+ export type { SearchSerializer, SearchParser } from './searchParams'
133
+
134
+ export type { OptionalStructuralSharing } from './structuralSharing'
135
+
1
136
  export {
2
- createHashHistory,
3
- createBrowserHistory,
4
- createMemoryHistory,
5
- } from 'history'
6
-
7
- export { default as invariant } from 'tiny-invariant'
8
-
9
- export * from './frameworks'
10
- export * from './index'
11
- export * from './link'
12
- export * from './path'
13
- export * from './qss'
14
- export * from './route'
15
- export * from './routeConfig'
16
- export * from './routeInfo'
17
- export * from './routeMatch'
18
- export * from './router'
19
- export * from './searchParams'
20
- export * from './utils'
137
+ last,
138
+ functionalUpdate,
139
+ pick,
140
+ replaceEqualDeep,
141
+ isPlainObject,
142
+ isPlainArray,
143
+ deepEqual,
144
+ escapeJSON,
145
+ shallow,
146
+ createControlledPromise,
147
+ } from './utils'
148
+ export type {
149
+ NoInfer,
150
+ IsAny,
151
+ PickAsRequired,
152
+ PickRequired,
153
+ PickOptional,
154
+ WithoutEmpty,
155
+ Expand,
156
+ DeepPartial,
157
+ MakeDifferenceOptional,
158
+ IsUnion,
159
+ IsNonEmptyObject,
160
+ Assign,
161
+ IntersectAssign,
162
+ Timeout,
163
+ Updater,
164
+ NonNullableUpdater,
165
+ StringLiteral,
166
+ ThrowOrOptional,
167
+ ControlledPromise,
168
+ ExtractObjects,
169
+ PartialMergeAllObject,
170
+ MergeAllPrimitive,
171
+ ExtractPrimitives,
172
+ PartialMergeAll,
173
+ Constrain,
174
+ ConstrainLiteral,
175
+ UnionToIntersection,
176
+ MergeAllObjects,
177
+ MergeAll,
178
+ ValidateJSON,
179
+ } from './utils'
180
+
181
+ export type {
182
+ StandardSchemaValidatorProps,
183
+ StandardSchemaValidator,
184
+ AnyStandardSchemaValidator,
185
+ StandardSchemaValidatorTypes,
186
+ AnyStandardSchemaValidateSuccess,
187
+ AnyStandardSchemaValidateFailure,
188
+ AnyStandardSchemaValidateIssue,
189
+ AnyStandardSchemaValidateInput,
190
+ AnyStandardSchemaValidate,
191
+ ValidatorObj,
192
+ AnyValidatorObj,
193
+ ValidatorAdapter,
194
+ AnyValidatorAdapter,
195
+ AnyValidatorFn,
196
+ ValidatorFn,
197
+ Validator,
198
+ AnyValidator,
199
+ AnySchema,
200
+ DefaultValidator,
201
+ ResolveSearchValidatorInputFn,
202
+ ResolveSearchValidatorInput,
203
+ ResolveValidatorInputFn,
204
+ ResolveValidatorInput,
205
+ ResolveValidatorOutputFn,
206
+ ResolveValidatorOutput,
207
+ } from './validators'