@tanstack/react-router 1.97.20 → 1.97.23

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 (182) hide show
  1. package/dist/cjs/Match.cjs +4 -5
  2. package/dist/cjs/Match.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +0 -10
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/Matches.d.cts +3 -30
  6. package/dist/cjs/RouterProvider.cjs.map +1 -1
  7. package/dist/cjs/RouterProvider.d.cts +2 -2
  8. package/dist/cjs/Transitioner.cjs +2 -2
  9. package/dist/cjs/Transitioner.cjs.map +1 -1
  10. package/dist/cjs/awaited.cjs +6 -6
  11. package/dist/cjs/awaited.cjs.map +1 -1
  12. package/dist/cjs/awaited.d.cts +1 -1
  13. package/dist/cjs/fileRoute.cjs.map +1 -1
  14. package/dist/cjs/fileRoute.d.cts +2 -3
  15. package/dist/cjs/index.cjs +136 -42
  16. package/dist/cjs/index.cjs.map +1 -1
  17. package/dist/cjs/index.d.cts +12 -26
  18. package/dist/cjs/link.cjs +8 -9
  19. package/dist/cjs/link.cjs.map +1 -1
  20. package/dist/cjs/link.d.cts +2 -49
  21. package/dist/cjs/redirects.cjs.map +1 -1
  22. package/dist/cjs/redirects.d.cts +1 -1
  23. package/dist/cjs/route.cjs +14 -15
  24. package/dist/cjs/route.cjs.map +1 -1
  25. package/dist/cjs/route.d.cts +2 -149
  26. package/dist/cjs/routeInfo.d.cts +2 -3
  27. package/dist/cjs/router.cjs +52 -71
  28. package/dist/cjs/router.cjs.map +1 -1
  29. package/dist/cjs/router.d.cts +4 -19
  30. package/dist/cjs/routerContext.d.cts +1 -1
  31. package/dist/cjs/scroll-restoration.cjs +2 -2
  32. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  33. package/dist/cjs/scroll-restoration.d.cts +1 -1
  34. package/dist/cjs/structuralSharing.d.cts +1 -4
  35. package/dist/cjs/typePrimitives.d.cts +1 -1
  36. package/dist/cjs/useLoaderData.cjs.map +1 -1
  37. package/dist/cjs/useLoaderData.d.cts +2 -1
  38. package/dist/cjs/useLoaderDeps.cjs.map +1 -1
  39. package/dist/cjs/useLoaderDeps.d.cts +2 -1
  40. package/dist/cjs/useMatch.cjs.map +1 -1
  41. package/dist/cjs/useMatch.d.cts +2 -1
  42. package/dist/cjs/useParams.cjs.map +1 -1
  43. package/dist/cjs/useParams.d.cts +2 -1
  44. package/dist/cjs/useRouteContext.cjs.map +1 -1
  45. package/dist/cjs/useRouteContext.d.cts +2 -1
  46. package/dist/cjs/useRouterState.cjs +2 -2
  47. package/dist/cjs/useRouterState.cjs.map +1 -1
  48. package/dist/cjs/useSearch.cjs.map +1 -1
  49. package/dist/cjs/useSearch.d.cts +2 -1
  50. package/dist/cjs/utils.cjs +0 -152
  51. package/dist/cjs/utils.cjs.map +1 -1
  52. package/dist/cjs/utils.d.cts +1 -81
  53. package/dist/esm/Match.js +1 -2
  54. package/dist/esm/Match.js.map +1 -1
  55. package/dist/esm/Matches.d.ts +3 -30
  56. package/dist/esm/Matches.js +0 -10
  57. package/dist/esm/Matches.js.map +1 -1
  58. package/dist/esm/RouterProvider.d.ts +2 -2
  59. package/dist/esm/RouterProvider.js.map +1 -1
  60. package/dist/esm/Transitioner.js +1 -1
  61. package/dist/esm/Transitioner.js.map +1 -1
  62. package/dist/esm/awaited.d.ts +1 -1
  63. package/dist/esm/awaited.js +1 -1
  64. package/dist/esm/awaited.js.map +1 -1
  65. package/dist/esm/fileRoute.d.ts +2 -3
  66. package/dist/esm/fileRoute.js.map +1 -1
  67. package/dist/esm/index.d.ts +12 -26
  68. package/dist/esm/index.js +5 -10
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/link.d.ts +2 -49
  71. package/dist/esm/link.js +2 -3
  72. package/dist/esm/link.js.map +1 -1
  73. package/dist/esm/redirects.d.ts +1 -1
  74. package/dist/esm/redirects.js.map +1 -1
  75. package/dist/esm/route.d.ts +2 -149
  76. package/dist/esm/route.js +1 -2
  77. package/dist/esm/route.js.map +1 -1
  78. package/dist/esm/routeInfo.d.ts +2 -3
  79. package/dist/esm/router.d.ts +4 -19
  80. package/dist/esm/router.js +2 -21
  81. package/dist/esm/router.js.map +1 -1
  82. package/dist/esm/routerContext.d.ts +1 -1
  83. package/dist/esm/scroll-restoration.d.ts +1 -1
  84. package/dist/esm/scroll-restoration.js +1 -1
  85. package/dist/esm/scroll-restoration.js.map +1 -1
  86. package/dist/esm/structuralSharing.d.ts +1 -4
  87. package/dist/esm/typePrimitives.d.ts +1 -1
  88. package/dist/esm/useLoaderData.d.ts +2 -1
  89. package/dist/esm/useLoaderData.js.map +1 -1
  90. package/dist/esm/useLoaderDeps.d.ts +2 -1
  91. package/dist/esm/useLoaderDeps.js.map +1 -1
  92. package/dist/esm/useMatch.d.ts +2 -1
  93. package/dist/esm/useMatch.js.map +1 -1
  94. package/dist/esm/useParams.d.ts +2 -1
  95. package/dist/esm/useParams.js.map +1 -1
  96. package/dist/esm/useRouteContext.d.ts +2 -1
  97. package/dist/esm/useRouteContext.js.map +1 -1
  98. package/dist/esm/useRouterState.js +1 -1
  99. package/dist/esm/useRouterState.js.map +1 -1
  100. package/dist/esm/useSearch.d.ts +2 -1
  101. package/dist/esm/useSearch.js.map +1 -1
  102. package/dist/esm/utils.d.ts +1 -81
  103. package/dist/esm/utils.js +0 -152
  104. package/dist/esm/utils.js.map +1 -1
  105. package/package.json +3 -2
  106. package/src/Match.tsx +5 -2
  107. package/src/Matches.tsx +8 -101
  108. package/src/RouterProvider.tsx +4 -2
  109. package/src/Transitioner.tsx +1 -1
  110. package/src/awaited.tsx +2 -2
  111. package/src/fileRoute.ts +6 -3
  112. package/src/index.tsx +128 -128
  113. package/src/link.tsx +27 -155
  114. package/src/redirects.ts +1 -1
  115. package/src/route.ts +41 -315
  116. package/src/routeInfo.ts +7 -3
  117. package/src/router.ts +33 -53
  118. package/src/scroll-restoration.tsx +2 -3
  119. package/src/structuralSharing.ts +5 -7
  120. package/src/typePrimitives.ts +1 -1
  121. package/src/useLoaderData.tsx +2 -1
  122. package/src/useLoaderDeps.tsx +2 -1
  123. package/src/useMatch.tsx +2 -1
  124. package/src/useParams.tsx +2 -1
  125. package/src/useRouteContext.ts +2 -1
  126. package/src/useRouterState.tsx +1 -1
  127. package/src/useSearch.tsx +2 -1
  128. package/src/utils.ts +1 -405
  129. package/dist/cjs/defer.cjs +0 -25
  130. package/dist/cjs/defer.cjs.map +0 -1
  131. package/dist/cjs/defer.d.cts +0 -20
  132. package/dist/cjs/location.d.cts +0 -12
  133. package/dist/cjs/manifest.d.cts +0 -24
  134. package/dist/cjs/path.cjs +0 -289
  135. package/dist/cjs/path.cjs.map +0 -1
  136. package/dist/cjs/path.d.cts +0 -34
  137. package/dist/cjs/qss.cjs +0 -51
  138. package/dist/cjs/qss.cjs.map +0 -1
  139. package/dist/cjs/qss.d.cts +0 -27
  140. package/dist/cjs/root.cjs +0 -5
  141. package/dist/cjs/root.cjs.map +0 -1
  142. package/dist/cjs/root.d.cts +0 -2
  143. package/dist/cjs/searchMiddleware.cjs +0 -42
  144. package/dist/cjs/searchMiddleware.cjs.map +0 -1
  145. package/dist/cjs/searchMiddleware.d.cts +0 -5
  146. package/dist/cjs/searchParams.cjs +0 -61
  147. package/dist/cjs/searchParams.cjs.map +0 -1
  148. package/dist/cjs/searchParams.d.cts +0 -7
  149. package/dist/cjs/serializer.d.cts +0 -15
  150. package/dist/cjs/validators.d.cts +0 -51
  151. package/dist/esm/defer.d.ts +0 -20
  152. package/dist/esm/defer.js +0 -25
  153. package/dist/esm/defer.js.map +0 -1
  154. package/dist/esm/location.d.ts +0 -12
  155. package/dist/esm/manifest.d.ts +0 -24
  156. package/dist/esm/path.d.ts +0 -34
  157. package/dist/esm/path.js +0 -289
  158. package/dist/esm/path.js.map +0 -1
  159. package/dist/esm/qss.d.ts +0 -27
  160. package/dist/esm/qss.js +0 -51
  161. package/dist/esm/qss.js.map +0 -1
  162. package/dist/esm/root.d.ts +0 -2
  163. package/dist/esm/root.js +0 -5
  164. package/dist/esm/root.js.map +0 -1
  165. package/dist/esm/searchMiddleware.d.ts +0 -5
  166. package/dist/esm/searchMiddleware.js +0 -42
  167. package/dist/esm/searchMiddleware.js.map +0 -1
  168. package/dist/esm/searchParams.d.ts +0 -7
  169. package/dist/esm/searchParams.js +0 -61
  170. package/dist/esm/searchParams.js.map +0 -1
  171. package/dist/esm/serializer.d.ts +0 -15
  172. package/dist/esm/validators.d.ts +0 -51
  173. package/src/defer.ts +0 -52
  174. package/src/location.ts +0 -13
  175. package/src/manifest.ts +0 -32
  176. package/src/path.ts +0 -427
  177. package/src/qss.ts +0 -91
  178. package/src/root.ts +0 -2
  179. package/src/searchMiddleware.ts +0 -54
  180. package/src/searchParams.ts +0 -77
  181. package/src/serializer.ts +0 -24
  182. package/src/validators.ts +0 -121
@@ -1 +0,0 @@
1
- {"version":3,"file":"searchMiddleware.js","sources":["../../src/searchMiddleware.ts"],"sourcesContent":["import { deepEqual } from './utils'\nimport type { NoInfer, PickOptional } from './utils'\nimport type { SearchMiddleware } from './route'\nimport type { IsRequiredParams } from './link'\n\nexport function retainSearchParams<TSearchSchema extends object>(\n keys: Array<keyof TSearchSchema> | true,\n): SearchMiddleware<TSearchSchema> {\n return ({ search, next }) => {\n const result = next(search)\n if (keys === true) {\n return { ...search, ...result }\n }\n // add missing keys from search to result\n keys.forEach((key) => {\n if (!(key in result)) {\n result[key] = search[key]\n }\n })\n return result\n }\n}\n\nexport function stripSearchParams<\n TSearchSchema,\n TOptionalProps = PickOptional<NoInfer<TSearchSchema>>,\n const TValues =\n | Partial<NoInfer<TOptionalProps>>\n | Array<keyof TOptionalProps>,\n const TInput = IsRequiredParams<TSearchSchema> extends never\n ? TValues | true\n : TValues,\n>(input: NoInfer<TInput>): SearchMiddleware<TSearchSchema> {\n return ({ search, next }) => {\n if (input === true) {\n return {}\n }\n const result = next(search) as Record<string, unknown>\n if (Array.isArray(input)) {\n input.forEach((key) => {\n delete result[key]\n })\n } else {\n Object.entries(input as Record<string, unknown>).forEach(\n ([key, value]) => {\n if (deepEqual(result[key], value)) {\n delete result[key]\n }\n },\n )\n }\n return result as any\n }\n}\n"],"names":[],"mappings":";AAKO,SAAS,mBACd,MACiC;AACjC,SAAO,CAAC,EAAE,QAAQ,WAAW;AACrB,UAAA,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,MAAM;AACjB,aAAO,EAAE,GAAG,QAAQ,GAAG,OAAO;AAAA,IAAA;AAG3B,SAAA,QAAQ,CAAC,QAAQ;AAChB,UAAA,EAAE,OAAO,SAAS;AACb,eAAA,GAAG,IAAI,OAAO,GAAG;AAAA,MAAA;AAAA,IAC1B,CACD;AACM,WAAA;AAAA,EACT;AACF;AAEO,SAAS,kBASd,OAAyD;AACzD,SAAO,CAAC,EAAE,QAAQ,WAAW;AAC3B,QAAI,UAAU,MAAM;AAClB,aAAO,CAAC;AAAA,IAAA;AAEJ,UAAA,SAAS,KAAK,MAAM;AACtB,QAAA,MAAM,QAAQ,KAAK,GAAG;AAClB,YAAA,QAAQ,CAAC,QAAQ;AACrB,eAAO,OAAO,GAAG;AAAA,MAAA,CAClB;AAAA,IAAA,OACI;AACE,aAAA,QAAQ,KAAgC,EAAE;AAAA,QAC/C,CAAC,CAAC,KAAK,KAAK,MAAM;AAChB,cAAI,UAAU,OAAO,GAAG,GAAG,KAAK,GAAG;AACjC,mBAAO,OAAO,GAAG;AAAA,UAAA;AAAA,QACnB;AAAA,MAEJ;AAAA,IAAA;AAEK,WAAA;AAAA,EACT;AACF;"}
@@ -1,7 +0,0 @@
1
- import { AnySchema } from './validators.js';
2
- export declare const defaultParseSearch: (searchStr: string) => AnySchema;
3
- export declare const defaultStringifySearch: (search: Record<string, any>) => string;
4
- export declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySchema;
5
- export declare function stringifySearchWith(stringify: (search: any) => string, parser?: (str: string) => any): (search: Record<string, any>) => string;
6
- export type SearchSerializer = (searchObj: Record<string, any>) => string;
7
- export type SearchParser = (searchStr: string) => Record<string, any>;
@@ -1,61 +0,0 @@
1
- import { decode, encode } from "./qss.js";
2
- const defaultParseSearch = parseSearchWith(JSON.parse);
3
- const defaultStringifySearch = stringifySearchWith(
4
- JSON.stringify,
5
- JSON.parse
6
- );
7
- function parseSearchWith(parser) {
8
- return (searchStr) => {
9
- if (searchStr.substring(0, 1) === "?") {
10
- searchStr = searchStr.substring(1);
11
- }
12
- const query = decode(searchStr);
13
- for (const key in query) {
14
- const value = query[key];
15
- if (typeof value === "string") {
16
- try {
17
- query[key] = parser(value);
18
- } catch (err) {
19
- }
20
- }
21
- }
22
- return query;
23
- };
24
- }
25
- function stringifySearchWith(stringify, parser) {
26
- function stringifyValue(val) {
27
- if (typeof val === "object" && val !== null) {
28
- try {
29
- return stringify(val);
30
- } catch (err) {
31
- }
32
- } else if (typeof val === "string" && typeof parser === "function") {
33
- try {
34
- parser(val);
35
- return stringify(val);
36
- } catch (err) {
37
- }
38
- }
39
- return val;
40
- }
41
- return (search) => {
42
- search = { ...search };
43
- Object.keys(search).forEach((key) => {
44
- const val = search[key];
45
- if (typeof val === "undefined" || val === void 0) {
46
- delete search[key];
47
- } else {
48
- search[key] = stringifyValue(val);
49
- }
50
- });
51
- const searchStr = encode(search).toString();
52
- return searchStr ? `?${searchStr}` : "";
53
- };
54
- }
55
- export {
56
- defaultParseSearch,
57
- defaultStringifySearch,
58
- parseSearchWith,
59
- stringifySearchWith
60
- };
61
- //# sourceMappingURL=searchParams.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"searchParams.js","sources":["../../src/searchParams.ts"],"sourcesContent":["import { decode, encode } from './qss'\nimport type { AnySchema } from './validators'\n\nexport const defaultParseSearch = parseSearchWith(JSON.parse)\nexport const defaultStringifySearch = stringifySearchWith(\n JSON.stringify,\n JSON.parse,\n)\n\nexport function parseSearchWith(parser: (str: string) => any) {\n return (searchStr: string): AnySchema => {\n if (searchStr.substring(0, 1) === '?') {\n searchStr = searchStr.substring(1)\n }\n\n const query: Record<string, unknown> = decode(searchStr)\n\n // Try to parse any query params that might be json\n for (const key in query) {\n const value = query[key]\n if (typeof value === 'string') {\n try {\n query[key] = parser(value)\n } catch (err) {\n //\n }\n }\n }\n\n return query\n }\n}\n\nexport function stringifySearchWith(\n stringify: (search: any) => string,\n parser?: (str: string) => any,\n) {\n function stringifyValue(val: any) {\n if (typeof val === 'object' && val !== null) {\n try {\n return stringify(val)\n } catch (err) {\n // silent\n }\n } else if (typeof val === 'string' && typeof parser === 'function') {\n try {\n // Check if it's a valid parseable string.\n // If it is, then stringify it again.\n parser(val)\n return stringify(val)\n } catch (err) {\n // silent\n }\n }\n return val\n }\n\n return (search: Record<string, any>) => {\n search = { ...search }\n\n Object.keys(search).forEach((key) => {\n const val = search[key]\n if (typeof val === 'undefined' || val === undefined) {\n delete search[key]\n } else {\n search[key] = stringifyValue(val)\n }\n })\n\n const searchStr = encode(search as Record<string, string>).toString()\n\n return searchStr ? `?${searchStr}` : ''\n }\n}\n\nexport type SearchSerializer = (searchObj: Record<string, any>) => string\nexport type SearchParser = (searchStr: string) => Record<string, any>\n"],"names":[],"mappings":";AAGa,MAAA,qBAAqB,gBAAgB,KAAK,KAAK;AACrD,MAAM,yBAAyB;AAAA,EACpC,KAAK;AAAA,EACL,KAAK;AACP;AAEO,SAAS,gBAAgB,QAA8B;AAC5D,SAAO,CAAC,cAAiC;AACvC,QAAI,UAAU,UAAU,GAAG,CAAC,MAAM,KAAK;AACzB,kBAAA,UAAU,UAAU,CAAC;AAAA,IAAA;AAG7B,UAAA,QAAiC,OAAO,SAAS;AAGvD,eAAW,OAAO,OAAO;AACjB,YAAA,QAAQ,MAAM,GAAG;AACnB,UAAA,OAAO,UAAU,UAAU;AACzB,YAAA;AACI,gBAAA,GAAG,IAAI,OAAO,KAAK;AAAA,iBAClB,KAAK;AAAA,QAAA;AAAA,MAEd;AAAA,IACF;AAGK,WAAA;AAAA,EACT;AACF;AAEgB,SAAA,oBACd,WACA,QACA;AACA,WAAS,eAAe,KAAU;AAChC,QAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM;AACvC,UAAA;AACF,eAAO,UAAU,GAAG;AAAA,eACb,KAAK;AAAA,MAAA;AAAA,eAGL,OAAO,QAAQ,YAAY,OAAO,WAAW,YAAY;AAC9D,UAAA;AAGF,eAAO,GAAG;AACV,eAAO,UAAU,GAAG;AAAA,eACb,KAAK;AAAA,MAAA;AAAA,IAEd;AAEK,WAAA;AAAA,EAAA;AAGT,SAAO,CAAC,WAAgC;AAC7B,aAAA,EAAE,GAAG,OAAO;AAErB,WAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAQ;AAC7B,YAAA,MAAM,OAAO,GAAG;AACtB,UAAI,OAAO,QAAQ,eAAe,QAAQ,QAAW;AACnD,eAAO,OAAO,GAAG;AAAA,MAAA,OACZ;AACE,eAAA,GAAG,IAAI,eAAe,GAAG;AAAA,MAAA;AAAA,IAClC,CACD;AAED,UAAM,YAAY,OAAO,MAAgC,EAAE,SAAS;AAE7D,WAAA,YAAY,IAAI,SAAS,KAAK;AAAA,EACvC;AACF;"}
@@ -1,15 +0,0 @@
1
- export interface StartSerializer {
2
- stringify: (obj: unknown) => string;
3
- parse: (str: string) => unknown;
4
- encode: <T>(value: T) => T;
5
- decode: <T>(value: T) => T;
6
- }
7
- export type SerializerStringifyBy<T, TSerializable> = T extends TSerializable ? T : T extends (...args: Array<any>) => any ? 'Function is not serializable' : {
8
- [K in keyof T]: SerializerStringifyBy<T[K], TSerializable>;
9
- };
10
- export type SerializerParseBy<T, TSerializable> = T extends TSerializable ? T : T extends React.JSX.Element ? ReadableStream : {
11
- [K in keyof T]: SerializerParseBy<T[K], TSerializable>;
12
- };
13
- export type Serializable = Date | undefined | Error | FormData;
14
- export type SerializerStringify<T> = SerializerStringifyBy<T, Serializable>;
15
- export type SerializerParse<T> = SerializerParseBy<T, Serializable>;
@@ -1,51 +0,0 @@
1
- import { SearchSchemaInput } from './route.js';
2
- export interface StandardSchemaValidatorProps<TInput, TOutput> {
3
- readonly types?: StandardSchemaValidatorTypes<TInput, TOutput> | undefined;
4
- readonly validate: AnyStandardSchemaValidate;
5
- }
6
- export interface StandardSchemaValidator<TInput, TOutput> {
7
- readonly '~standard': StandardSchemaValidatorProps<TInput, TOutput>;
8
- }
9
- export type AnyStandardSchemaValidator = StandardSchemaValidator<any, any>;
10
- export interface StandardSchemaValidatorTypes<TInput, TOutput> {
11
- readonly input: TInput;
12
- readonly output: TOutput;
13
- }
14
- export interface AnyStandardSchemaValidateSuccess {
15
- readonly value: any;
16
- readonly issues?: undefined;
17
- }
18
- export interface AnyStandardSchemaValidateFailure {
19
- readonly issues: ReadonlyArray<AnyStandardSchemaValidateIssue>;
20
- }
21
- export interface AnyStandardSchemaValidateIssue {
22
- readonly message: string;
23
- }
24
- export interface AnyStandardSchemaValidateInput {
25
- readonly value: any;
26
- }
27
- export type AnyStandardSchemaValidate = (value: unknown) => (AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure) | Promise<AnyStandardSchemaValidateSuccess | AnyStandardSchemaValidateFailure>;
28
- export interface ValidatorObj<TInput, TOutput> {
29
- parse: ValidatorFn<TInput, TOutput>;
30
- }
31
- export type AnyValidatorObj = ValidatorObj<any, any>;
32
- export interface ValidatorAdapter<TInput, TOutput> {
33
- types: {
34
- input: TInput;
35
- output: TOutput;
36
- };
37
- parse: (input: unknown) => TOutput;
38
- }
39
- export type AnyValidatorAdapter = ValidatorAdapter<any, any>;
40
- export type AnyValidatorFn = ValidatorFn<any, any>;
41
- export type ValidatorFn<TInput, TOutput> = (input: TInput) => TOutput;
42
- export type Validator<TInput, TOutput> = ValidatorObj<TInput, TOutput> | ValidatorFn<TInput, TOutput> | ValidatorAdapter<TInput, TOutput> | StandardSchemaValidator<TInput, TOutput> | undefined;
43
- export type AnyValidator = Validator<any, any>;
44
- export type AnySchema = {};
45
- export type DefaultValidator = Validator<Record<string, unknown>, AnySchema>;
46
- export type ResolveSearchValidatorInputFn<TValidator> = TValidator extends (input: infer TSchemaInput) => any ? TSchemaInput extends SearchSchemaInput ? Omit<TSchemaInput, keyof SearchSchemaInput> : ResolveValidatorOutputFn<TValidator> : AnySchema;
47
- export type ResolveSearchValidatorInput<TValidator> = TValidator extends AnyStandardSchemaValidator ? NonNullable<TValidator['~standard']['types']>['input'] : TValidator extends AnyValidatorAdapter ? TValidator['types']['input'] : TValidator extends AnyValidatorObj ? ResolveSearchValidatorInputFn<TValidator['parse']> : ResolveSearchValidatorInputFn<TValidator>;
48
- export type ResolveValidatorInputFn<TValidator> = TValidator extends (input: infer TInput) => any ? TInput : undefined;
49
- export type ResolveValidatorInput<TValidator> = TValidator extends AnyStandardSchemaValidator ? NonNullable<TValidator['~standard']['types']>['input'] : TValidator extends AnyValidatorAdapter ? TValidator['types']['input'] : TValidator extends AnyValidatorObj ? ResolveValidatorInputFn<TValidator['parse']> : ResolveValidatorInputFn<TValidator>;
50
- export type ResolveValidatorOutputFn<TValidator> = TValidator extends (...args: any) => infer TSchema ? TSchema : AnySchema;
51
- export type ResolveValidatorOutput<TValidator> = unknown extends TValidator ? TValidator : TValidator extends AnyStandardSchemaValidator ? NonNullable<TValidator['~standard']['types']>['output'] : TValidator extends AnyValidatorAdapter ? TValidator['types']['output'] : TValidator extends AnyValidatorObj ? ResolveValidatorOutputFn<TValidator['parse']> : ResolveValidatorOutputFn<TValidator>;
package/src/defer.ts DELETED
@@ -1,52 +0,0 @@
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/location.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { ParsedHistoryState } from '@tanstack/history'
2
- import type { AnySchema } from './validators'
3
-
4
- export interface ParsedLocation<TSearchObj extends AnySchema = {}> {
5
- href: string
6
- pathname: string
7
- search: TSearchObj
8
- searchStr: string
9
- state: ParsedHistoryState
10
- hash: string
11
- maskedLocation?: ParsedLocation<TSearchObj>
12
- unmaskOnReload?: boolean
13
- }
package/src/manifest.ts DELETED
@@ -1,32 +0,0 @@
1
- export type Manifest = {
2
- routes: Record<
3
- string,
4
- {
5
- filePath?: string
6
- preloads?: Array<string>
7
- assets?: Array<RouterManagedTag>
8
- }
9
- >
10
- }
11
-
12
- export type RouterManagedTag =
13
- | {
14
- tag: 'title'
15
- attrs?: Record<string, any>
16
- children: string
17
- }
18
- | {
19
- tag: 'meta' | 'link'
20
- attrs?: Record<string, any>
21
- children?: never
22
- }
23
- | {
24
- tag: 'script'
25
- attrs?: Record<string, any>
26
- children?: string
27
- }
28
- | {
29
- tag: 'style'
30
- attrs?: Record<string, any>
31
- children?: string
32
- }
package/src/path.ts DELETED
@@ -1,427 +0,0 @@
1
- import { last } from './utils'
2
- import type { MatchLocation } from './RouterProvider'
3
- import type { AnyPathParams } from './route'
4
-
5
- export interface Segment {
6
- type: 'pathname' | 'param' | 'wildcard'
7
- value: string
8
- }
9
-
10
- export function joinPaths(paths: Array<string | undefined>) {
11
- return cleanPath(
12
- paths
13
- .filter((val) => {
14
- return val !== undefined
15
- })
16
- .join('/'),
17
- )
18
- }
19
-
20
- export function cleanPath(path: string) {
21
- // remove double slashes
22
- return path.replace(/\/{2,}/g, '/')
23
- }
24
-
25
- export function trimPathLeft(path: string) {
26
- return path === '/' ? path : path.replace(/^\/{1,}/, '')
27
- }
28
-
29
- export function trimPathRight(path: string) {
30
- return path === '/' ? path : path.replace(/\/{1,}$/, '')
31
- }
32
-
33
- export function trimPath(path: string) {
34
- return trimPathRight(trimPathLeft(path))
35
- }
36
-
37
- export function removeTrailingSlash(value: string, basepath: string): string {
38
- if (value.endsWith('/') && value !== '/' && value !== `${basepath}/`) {
39
- return value.slice(0, -1)
40
- }
41
- return value
42
- }
43
-
44
- // intended to only compare path name
45
- // see the usage in the isActive under useLinkProps
46
- // /sample/path1 = /sample/path1/
47
- // /sample/path1/some <> /sample/path1
48
- export function exactPathTest(
49
- pathName1: string,
50
- pathName2: string,
51
- basepath: string,
52
- ): boolean {
53
- return (
54
- removeTrailingSlash(pathName1, basepath) ===
55
- removeTrailingSlash(pathName2, basepath)
56
- )
57
- }
58
-
59
- // When resolving relative paths, we treat all paths as if they are trailing slash
60
- // documents. All trailing slashes are removed after the path is resolved.
61
- // Here are a few examples:
62
- //
63
- // /a/b/c + ./d = /a/b/c/d
64
- // /a/b/c + ../d = /a/b/d
65
- // /a/b/c + ./d/ = /a/b/c/d
66
- // /a/b/c + ../d/ = /a/b/d
67
- // /a/b/c + ./ = /a/b/c
68
- //
69
- // Absolute paths that start with `/` short circuit the resolution process to the root
70
- // path.
71
- //
72
- // Here are some examples:
73
- //
74
- // /a/b/c + /d = /d
75
- // /a/b/c + /d/ = /d
76
- // /a/b/c + / = /
77
- //
78
- // Non-.-prefixed paths are still treated as relative paths, resolved like `./`
79
- //
80
- // Here are some examples:
81
- //
82
- // /a/b/c + d = /a/b/c/d
83
- // /a/b/c + d/ = /a/b/c/d
84
- // /a/b/c + d/e = /a/b/c/d/e
85
- interface ResolvePathOptions {
86
- basepath: string
87
- base: string
88
- to: string
89
- trailingSlash?: 'always' | 'never' | 'preserve'
90
- caseSensitive?: boolean
91
- }
92
-
93
- export function resolvePath({
94
- basepath,
95
- base,
96
- to,
97
- trailingSlash = 'never',
98
- caseSensitive,
99
- }: ResolvePathOptions) {
100
- base = removeBasepath(basepath, base, caseSensitive)
101
- to = removeBasepath(basepath, to, caseSensitive)
102
-
103
- let baseSegments = parsePathname(base)
104
- const toSegments = parsePathname(to)
105
-
106
- if (baseSegments.length > 1 && last(baseSegments)?.value === '/') {
107
- baseSegments.pop()
108
- }
109
-
110
- toSegments.forEach((toSegment, index) => {
111
- if (toSegment.value === '/') {
112
- if (!index) {
113
- // Leading slash
114
- baseSegments = [toSegment]
115
- } else if (index === toSegments.length - 1) {
116
- // Trailing Slash
117
- baseSegments.push(toSegment)
118
- } else {
119
- // ignore inter-slashes
120
- }
121
- } else if (toSegment.value === '..') {
122
- baseSegments.pop()
123
- } else if (toSegment.value === '.') {
124
- // ignore
125
- } else {
126
- baseSegments.push(toSegment)
127
- }
128
- })
129
-
130
- if (baseSegments.length > 1) {
131
- if (last(baseSegments)?.value === '/') {
132
- if (trailingSlash === 'never') {
133
- baseSegments.pop()
134
- }
135
- } else if (trailingSlash === 'always') {
136
- baseSegments.push({ type: 'pathname', value: '/' })
137
- }
138
- }
139
-
140
- const joined = joinPaths([basepath, ...baseSegments.map((d) => d.value)])
141
- return cleanPath(joined)
142
- }
143
-
144
- export function parsePathname(pathname?: string): Array<Segment> {
145
- if (!pathname) {
146
- return []
147
- }
148
-
149
- pathname = cleanPath(pathname)
150
-
151
- const segments: Array<Segment> = []
152
-
153
- if (pathname.slice(0, 1) === '/') {
154
- pathname = pathname.substring(1)
155
- segments.push({
156
- type: 'pathname',
157
- value: '/',
158
- })
159
- }
160
-
161
- if (!pathname) {
162
- return segments
163
- }
164
-
165
- // Remove empty segments and '.' segments
166
- const split = pathname.split('/').filter(Boolean)
167
-
168
- segments.push(
169
- ...split.map((part): Segment => {
170
- if (part === '$' || part === '*') {
171
- return {
172
- type: 'wildcard',
173
- value: part,
174
- }
175
- }
176
-
177
- if (part.charAt(0) === '$') {
178
- return {
179
- type: 'param',
180
- value: part,
181
- }
182
- }
183
-
184
- return {
185
- type: 'pathname',
186
- value: decodeURI(part),
187
- }
188
- }),
189
- )
190
-
191
- if (pathname.slice(-1) === '/') {
192
- pathname = pathname.substring(1)
193
- segments.push({
194
- type: 'pathname',
195
- value: '/',
196
- })
197
- }
198
-
199
- return segments
200
- }
201
-
202
- interface InterpolatePathOptions {
203
- path?: string
204
- params: Record<string, unknown>
205
- leaveWildcards?: boolean
206
- leaveParams?: boolean
207
- // Map of encoded chars to decoded chars (e.g. '%40' -> '@') that should remain decoded in path params
208
- decodeCharMap?: Map<string, string>
209
- }
210
-
211
- export function interpolatePath({
212
- path,
213
- params,
214
- leaveWildcards,
215
- leaveParams,
216
- decodeCharMap,
217
- }: InterpolatePathOptions) {
218
- const interpolatedPathSegments = parsePathname(path)
219
- const encodedParams: any = {}
220
-
221
- for (const [key, value] of Object.entries(params)) {
222
- const isValueString = typeof value === 'string'
223
-
224
- if (['*', '_splat'].includes(key)) {
225
- // the splat/catch-all routes shouldn't have the '/' encoded out
226
- encodedParams[key] = isValueString ? encodeURI(value) : value
227
- } else {
228
- encodedParams[key] = isValueString
229
- ? encodePathParam(value, decodeCharMap)
230
- : value
231
- }
232
- }
233
-
234
- return joinPaths(
235
- interpolatedPathSegments.map((segment) => {
236
- if (segment.type === 'wildcard') {
237
- const value = encodedParams._splat
238
- if (leaveWildcards) return `${segment.value}${value ?? ''}`
239
- return value
240
- }
241
-
242
- if (segment.type === 'param') {
243
- if (leaveParams) {
244
- const value = encodedParams[segment.value]
245
- return `${segment.value}${value ?? ''}`
246
- }
247
- return encodedParams![segment.value.substring(1)] ?? 'undefined'
248
- }
249
-
250
- return segment.value
251
- }),
252
- )
253
- }
254
-
255
- function encodePathParam(value: string, decodeCharMap?: Map<string, string>) {
256
- let encoded = encodeURIComponent(value)
257
- if (decodeCharMap) {
258
- for (const [encodedChar, char] of decodeCharMap) {
259
- encoded = encoded.replaceAll(encodedChar, char)
260
- }
261
- }
262
- return encoded
263
- }
264
-
265
- export function matchPathname(
266
- basepath: string,
267
- currentPathname: string,
268
- matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,
269
- ): AnyPathParams | undefined {
270
- const pathParams = matchByPath(basepath, currentPathname, matchLocation)
271
- // const searchMatched = matchBySearch(location.search, matchLocation)
272
-
273
- if (matchLocation.to && !pathParams) {
274
- return
275
- }
276
-
277
- return pathParams ?? {}
278
- }
279
-
280
- export function removeBasepath(
281
- basepath: string,
282
- pathname: string,
283
- caseSensitive: boolean = false,
284
- ) {
285
- // normalize basepath and pathname for case-insensitive comparison if needed
286
- const normalizedBasepath = caseSensitive ? basepath : basepath.toLowerCase()
287
- const normalizedPathname = caseSensitive ? pathname : pathname.toLowerCase()
288
-
289
- switch (true) {
290
- // default behaviour is to serve app from the root - pathname
291
- // left untouched
292
- case normalizedBasepath === '/':
293
- return pathname
294
-
295
- // shortcut for removing the basepath if it matches the pathname
296
- case normalizedPathname === normalizedBasepath:
297
- return ''
298
-
299
- // in case pathname is shorter than basepath - there is
300
- // nothing to remove
301
- case pathname.length < basepath.length:
302
- return pathname
303
-
304
- // avoid matching partial segments - strict equality handled
305
- // earlier, otherwise, basepath separated from pathname with
306
- // separator, therefore lack of separator means partial
307
- // segment match (`/app` should not match `/application`)
308
- case normalizedPathname[normalizedBasepath.length] !== '/':
309
- return pathname
310
-
311
- // remove the basepath from the pathname if it starts with it
312
- case normalizedPathname.startsWith(normalizedBasepath):
313
- return pathname.slice(basepath.length)
314
-
315
- // otherwise, return the pathname as is
316
- default:
317
- return pathname
318
- }
319
- }
320
-
321
- export function matchByPath(
322
- basepath: string,
323
- from: string,
324
- matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
325
- ): Record<string, string> | undefined {
326
- // check basepath first
327
- if (basepath !== '/' && !from.startsWith(basepath)) {
328
- return undefined
329
- }
330
- // Remove the base path from the pathname
331
- from = removeBasepath(basepath, from, matchLocation.caseSensitive)
332
- // Default to to $ (wildcard)
333
- const to = removeBasepath(
334
- basepath,
335
- `${matchLocation.to ?? '$'}`,
336
- matchLocation.caseSensitive,
337
- )
338
-
339
- // Parse the from and to
340
- const baseSegments = parsePathname(from)
341
- const routeSegments = parsePathname(to)
342
-
343
- if (!from.startsWith('/')) {
344
- baseSegments.unshift({
345
- type: 'pathname',
346
- value: '/',
347
- })
348
- }
349
-
350
- if (!to.startsWith('/')) {
351
- routeSegments.unshift({
352
- type: 'pathname',
353
- value: '/',
354
- })
355
- }
356
-
357
- const params: Record<string, string> = {}
358
-
359
- const isMatch = (() => {
360
- for (
361
- let i = 0;
362
- i < Math.max(baseSegments.length, routeSegments.length);
363
- i++
364
- ) {
365
- const baseSegment = baseSegments[i]
366
- const routeSegment = routeSegments[i]
367
-
368
- const isLastBaseSegment = i >= baseSegments.length - 1
369
- const isLastRouteSegment = i >= routeSegments.length - 1
370
-
371
- if (routeSegment) {
372
- if (routeSegment.type === 'wildcard') {
373
- const _splat = decodeURI(
374
- joinPaths(baseSegments.slice(i).map((d) => d.value)),
375
- )
376
- // TODO: Deprecate *
377
- params['*'] = _splat
378
- params['_splat'] = _splat
379
- return true
380
- }
381
-
382
- if (routeSegment.type === 'pathname') {
383
- if (routeSegment.value === '/' && !baseSegment?.value) {
384
- return true
385
- }
386
-
387
- if (baseSegment) {
388
- if (matchLocation.caseSensitive) {
389
- if (routeSegment.value !== baseSegment.value) {
390
- return false
391
- }
392
- } else if (
393
- routeSegment.value.toLowerCase() !==
394
- baseSegment.value.toLowerCase()
395
- ) {
396
- return false
397
- }
398
- }
399
- }
400
-
401
- if (!baseSegment) {
402
- return false
403
- }
404
-
405
- if (routeSegment.type === 'param') {
406
- if (baseSegment.value === '/') {
407
- return false
408
- }
409
- if (baseSegment.value.charAt(0) !== '$') {
410
- params[routeSegment.value.substring(1)] = decodeURIComponent(
411
- baseSegment.value,
412
- )
413
- }
414
- }
415
- }
416
-
417
- if (!isLastBaseSegment && isLastRouteSegment) {
418
- params['**'] = joinPaths(baseSegments.slice(i + 1).map((d) => d.value))
419
- return !!matchLocation.fuzzy && routeSegment?.value !== '/'
420
- }
421
- }
422
-
423
- return true
424
- })()
425
-
426
- return isMatch ? params : undefined
427
- }