@tanstack/router-core 1.167.0 → 1.167.2

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 (166) hide show
  1. package/dist/cjs/Matches.cjs +15 -12
  2. package/dist/cjs/Matches.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  4. package/dist/cjs/config.cjs +9 -8
  5. package/dist/cjs/config.cjs.map +1 -1
  6. package/dist/cjs/defer.cjs +37 -21
  7. package/dist/cjs/defer.cjs.map +1 -1
  8. package/dist/cjs/index.cjs +87 -89
  9. package/dist/cjs/isServer/client.cjs +5 -3
  10. package/dist/cjs/isServer/client.cjs.map +1 -1
  11. package/dist/cjs/isServer/development.cjs +5 -3
  12. package/dist/cjs/isServer/development.cjs.map +1 -1
  13. package/dist/cjs/isServer/server.cjs +5 -3
  14. package/dist/cjs/isServer/server.cjs.map +1 -1
  15. package/dist/cjs/link.cjs +5 -4
  16. package/dist/cjs/link.cjs.map +1 -1
  17. package/dist/cjs/load-matches.cjs +619 -766
  18. package/dist/cjs/load-matches.cjs.map +1 -1
  19. package/dist/cjs/lru-cache.cjs +67 -64
  20. package/dist/cjs/lru-cache.cjs.map +1 -1
  21. package/dist/cjs/new-process-route-tree.cjs +707 -792
  22. package/dist/cjs/new-process-route-tree.cjs.map +1 -1
  23. package/dist/cjs/not-found.cjs +20 -7
  24. package/dist/cjs/not-found.cjs.map +1 -1
  25. package/dist/cjs/path.cjs +221 -232
  26. package/dist/cjs/path.cjs.map +1 -1
  27. package/dist/cjs/qss.cjs +62 -28
  28. package/dist/cjs/qss.cjs.map +1 -1
  29. package/dist/cjs/redirect.cjs +44 -30
  30. package/dist/cjs/redirect.cjs.map +1 -1
  31. package/dist/cjs/rewrite.cjs +56 -56
  32. package/dist/cjs/rewrite.cjs.map +1 -1
  33. package/dist/cjs/root.cjs +6 -4
  34. package/dist/cjs/root.cjs.map +1 -1
  35. package/dist/cjs/route.cjs +96 -105
  36. package/dist/cjs/route.cjs.map +1 -1
  37. package/dist/cjs/router.cjs +1153 -1524
  38. package/dist/cjs/router.cjs.map +1 -1
  39. package/dist/cjs/router.d.cts +2 -0
  40. package/dist/cjs/scroll-restoration.cjs +189 -207
  41. package/dist/cjs/scroll-restoration.cjs.map +1 -1
  42. package/dist/cjs/searchMiddleware.cjs +48 -37
  43. package/dist/cjs/searchMiddleware.cjs.map +1 -1
  44. package/dist/cjs/searchParams.cjs +57 -45
  45. package/dist/cjs/searchParams.cjs.map +1 -1
  46. package/dist/cjs/ssr/client.cjs +6 -8
  47. package/dist/cjs/ssr/constants.cjs +6 -5
  48. package/dist/cjs/ssr/constants.cjs.map +1 -1
  49. package/dist/cjs/ssr/createRequestHandler.cjs +41 -59
  50. package/dist/cjs/ssr/createRequestHandler.cjs.map +1 -1
  51. package/dist/cjs/ssr/handlerCallback.cjs +5 -4
  52. package/dist/cjs/ssr/handlerCallback.cjs.map +1 -1
  53. package/dist/cjs/ssr/headers.cjs +17 -26
  54. package/dist/cjs/ssr/headers.cjs.map +1 -1
  55. package/dist/cjs/ssr/json.cjs +8 -4
  56. package/dist/cjs/ssr/json.cjs.map +1 -1
  57. package/dist/cjs/ssr/serializer/RawStream.cjs +268 -268
  58. package/dist/cjs/ssr/serializer/RawStream.cjs.map +1 -1
  59. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs +31 -32
  60. package/dist/cjs/ssr/serializer/ShallowErrorPlugin.cjs.map +1 -1
  61. package/dist/cjs/ssr/serializer/seroval-plugins.cjs +12 -12
  62. package/dist/cjs/ssr/serializer/seroval-plugins.cjs.map +1 -1
  63. package/dist/cjs/ssr/serializer/transformer.cjs +45 -41
  64. package/dist/cjs/ssr/serializer/transformer.cjs.map +1 -1
  65. package/dist/cjs/ssr/server.cjs +12 -14
  66. package/dist/cjs/ssr/ssr-client.cjs +173 -211
  67. package/dist/cjs/ssr/ssr-client.cjs.map +1 -1
  68. package/dist/cjs/ssr/ssr-match-id.cjs +6 -5
  69. package/dist/cjs/ssr/ssr-match-id.cjs.map +1 -1
  70. package/dist/cjs/ssr/ssr-server.cjs +266 -300
  71. package/dist/cjs/ssr/ssr-server.cjs.map +1 -1
  72. package/dist/cjs/ssr/transformStreamWithRouter.cjs +317 -337
  73. package/dist/cjs/ssr/transformStreamWithRouter.cjs.map +1 -1
  74. package/dist/cjs/ssr/tsrScript.cjs +6 -4
  75. package/dist/cjs/ssr/tsrScript.cjs.map +1 -1
  76. package/dist/cjs/ssr/tsrScript.d.cts +1 -0
  77. package/dist/cjs/utils/batch.cjs +13 -13
  78. package/dist/cjs/utils/batch.cjs.map +1 -1
  79. package/dist/cjs/utils.cjs +274 -208
  80. package/dist/cjs/utils.cjs.map +1 -1
  81. package/dist/esm/Matches.js +16 -13
  82. package/dist/esm/Matches.js.map +1 -1
  83. package/dist/esm/config.js +10 -9
  84. package/dist/esm/config.js.map +1 -1
  85. package/dist/esm/defer.js +37 -22
  86. package/dist/esm/defer.js.map +1 -1
  87. package/dist/esm/index.js +12 -82
  88. package/dist/esm/isServer/client.js +6 -5
  89. package/dist/esm/isServer/client.js.map +1 -1
  90. package/dist/esm/isServer/development.js +6 -5
  91. package/dist/esm/isServer/development.js.map +1 -1
  92. package/dist/esm/isServer/server.js +6 -5
  93. package/dist/esm/isServer/server.js.map +1 -1
  94. package/dist/esm/link.js +6 -5
  95. package/dist/esm/link.js.map +1 -1
  96. package/dist/esm/load-matches.js +614 -765
  97. package/dist/esm/load-matches.js.map +1 -1
  98. package/dist/esm/lru-cache.js +68 -65
  99. package/dist/esm/lru-cache.js.map +1 -1
  100. package/dist/esm/new-process-route-tree.js +705 -797
  101. package/dist/esm/new-process-route-tree.js.map +1 -1
  102. package/dist/esm/not-found.js +21 -9
  103. package/dist/esm/not-found.js.map +1 -1
  104. package/dist/esm/path.js +220 -241
  105. package/dist/esm/path.js.map +1 -1
  106. package/dist/esm/qss.js +63 -30
  107. package/dist/esm/qss.js.map +1 -1
  108. package/dist/esm/redirect.js +45 -34
  109. package/dist/esm/redirect.js.map +1 -1
  110. package/dist/esm/rewrite.js +57 -60
  111. package/dist/esm/rewrite.js.map +1 -1
  112. package/dist/esm/root.js +7 -5
  113. package/dist/esm/root.js.map +1 -1
  114. package/dist/esm/route.js +92 -105
  115. package/dist/esm/route.js.map +1 -1
  116. package/dist/esm/router.d.ts +2 -0
  117. package/dist/esm/router.js +1147 -1527
  118. package/dist/esm/router.js.map +1 -1
  119. package/dist/esm/scroll-restoration.js +188 -213
  120. package/dist/esm/scroll-restoration.js.map +1 -1
  121. package/dist/esm/searchMiddleware.js +48 -38
  122. package/dist/esm/searchMiddleware.js.map +1 -1
  123. package/dist/esm/searchParams.js +57 -48
  124. package/dist/esm/searchParams.js.map +1 -1
  125. package/dist/esm/ssr/client.js +1 -6
  126. package/dist/esm/ssr/constants.js +7 -7
  127. package/dist/esm/ssr/constants.js.map +1 -1
  128. package/dist/esm/ssr/createRequestHandler.js +39 -58
  129. package/dist/esm/ssr/createRequestHandler.js.map +1 -1
  130. package/dist/esm/ssr/handlerCallback.js +6 -5
  131. package/dist/esm/ssr/handlerCallback.js.map +1 -1
  132. package/dist/esm/ssr/headers.js +16 -26
  133. package/dist/esm/ssr/headers.js.map +1 -1
  134. package/dist/esm/ssr/json.js +9 -5
  135. package/dist/esm/ssr/json.js.map +1 -1
  136. package/dist/esm/ssr/serializer/RawStream.js +267 -273
  137. package/dist/esm/ssr/serializer/RawStream.js.map +1 -1
  138. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js +31 -32
  139. package/dist/esm/ssr/serializer/ShallowErrorPlugin.js.map +1 -1
  140. package/dist/esm/ssr/serializer/seroval-plugins.js +10 -11
  141. package/dist/esm/ssr/serializer/seroval-plugins.js.map +1 -1
  142. package/dist/esm/ssr/serializer/transformer.js +44 -43
  143. package/dist/esm/ssr/serializer/transformer.js.map +1 -1
  144. package/dist/esm/ssr/server.js +2 -12
  145. package/dist/esm/ssr/ssr-client.js +169 -209
  146. package/dist/esm/ssr/ssr-client.js.map +1 -1
  147. package/dist/esm/ssr/ssr-match-id.js +7 -7
  148. package/dist/esm/ssr/ssr-match-id.js.map +1 -1
  149. package/dist/esm/ssr/ssr-server.js +262 -300
  150. package/dist/esm/ssr/ssr-server.js.map +1 -1
  151. package/dist/esm/ssr/transformStreamWithRouter.js +315 -338
  152. package/dist/esm/ssr/transformStreamWithRouter.js.map +1 -1
  153. package/dist/esm/ssr/tsrScript.js +6 -5
  154. package/dist/esm/ssr/tsrScript.js.map +1 -1
  155. package/dist/esm/utils/batch.js +13 -14
  156. package/dist/esm/utils/batch.js.map +1 -1
  157. package/dist/esm/utils.js +273 -224
  158. package/dist/esm/utils.js.map +1 -1
  159. package/package.json +2 -2
  160. package/src/router.ts +2 -0
  161. package/dist/cjs/index.cjs.map +0 -1
  162. package/dist/cjs/ssr/client.cjs.map +0 -1
  163. package/dist/cjs/ssr/server.cjs.map +0 -1
  164. package/dist/esm/index.js.map +0 -1
  165. package/dist/esm/ssr/client.js.map +0 -1
  166. package/dist/esm/ssr/server.js.map +0 -1
package/dist/cjs/qss.cjs CHANGED
@@ -1,36 +1,70 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
+ //#region src/qss.ts
2
+ /**
3
+ * Program is a reimplementation of the `qss` package:
4
+ * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License
5
+ * https://github.com/lukeed/qss/blob/master/license.md
6
+ *
7
+ * This reimplementation uses modern browser APIs
8
+ * (namely URLSearchParams) and TypeScript while still
9
+ * maintaining the original functionality and interface.
10
+ *
11
+ * Update: this implementation has also been mangled to
12
+ * fit exactly our use-case (single value per key in encoding).
13
+ */
14
+ /**
15
+ * Encodes an object into a query string.
16
+ * @param obj - The object to encode into a query string.
17
+ * @param stringify - An optional custom stringify function.
18
+ * @returns The encoded query string.
19
+ * @example
20
+ * ```
21
+ * // Example input: encode({ token: 'foo', key: 'value' })
22
+ * // Expected output: "token=foo&key=value"
23
+ * ```
24
+ */
3
25
  function encode(obj, stringify = String) {
4
- const result = new URLSearchParams();
5
- for (const key in obj) {
6
- const val = obj[key];
7
- if (val !== void 0) {
8
- result.set(key, stringify(val));
9
- }
10
- }
11
- return result.toString();
26
+ const result = new URLSearchParams();
27
+ for (const key in obj) {
28
+ const val = obj[key];
29
+ if (val !== void 0) result.set(key, stringify(val));
30
+ }
31
+ return result.toString();
12
32
  }
33
+ /**
34
+ * Converts a string value to its appropriate type (string, number, boolean).
35
+ * @param mix - The string value to convert.
36
+ * @returns The converted value.
37
+ * @example
38
+ * // Example input: toValue("123")
39
+ * // Expected output: 123
40
+ */
13
41
  function toValue(str) {
14
- if (!str) return "";
15
- if (str === "false") return false;
16
- if (str === "true") return true;
17
- return +str * 0 === 0 && +str + "" === str ? +str : str;
42
+ if (!str) return "";
43
+ if (str === "false") return false;
44
+ if (str === "true") return true;
45
+ return +str * 0 === 0 && +str + "" === str ? +str : str;
18
46
  }
47
+ /**
48
+ * Decodes a query string into an object.
49
+ * @param str - The query string to decode.
50
+ * @returns The decoded key-value pairs in an object format.
51
+ * @example
52
+ * // Example input: decode("token=foo&key=value")
53
+ * // Expected output: { "token": "foo", "key": "value" }
54
+ */
19
55
  function decode(str) {
20
- const searchParams = new URLSearchParams(str);
21
- const result = /* @__PURE__ */ Object.create(null);
22
- for (const [key, value] of searchParams.entries()) {
23
- const previousValue = result[key];
24
- if (previousValue == null) {
25
- result[key] = toValue(value);
26
- } else if (Array.isArray(previousValue)) {
27
- previousValue.push(toValue(value));
28
- } else {
29
- result[key] = [previousValue, toValue(value)];
30
- }
31
- }
32
- return result;
56
+ const searchParams = new URLSearchParams(str);
57
+ const result = Object.create(null);
58
+ for (const [key, value] of searchParams.entries()) {
59
+ const previousValue = result[key];
60
+ if (previousValue == null) result[key] = toValue(value);
61
+ else if (Array.isArray(previousValue)) previousValue.push(toValue(value));
62
+ else result[key] = [previousValue, toValue(value)];
63
+ }
64
+ return result;
33
65
  }
66
+ //#endregion
34
67
  exports.decode = decode;
35
68
  exports.encode = encode;
36
- //# sourceMappingURL=qss.cjs.map
69
+
70
+ //# sourceMappingURL=qss.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"qss.cjs","sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n *\n * Update: this implementation has also been mangled to\n * fit exactly our use-case (single value per key in encoding).\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param stringify - An optional custom stringify function.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(\n obj: Record<string, any>,\n stringify: (value: any) => string = String,\n): string {\n const result = new URLSearchParams()\n\n for (const key in obj) {\n const val = obj[key]\n if (val !== undefined) {\n result.set(key, stringify(val))\n }\n }\n\n return result.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any): any {\n const searchParams = new URLSearchParams(str)\n\n const result: Record<string, unknown> = Object.create(null)\n\n for (const [key, value] of searchParams.entries()) {\n const previousValue = result[key]\n if (previousValue == null) {\n result[key] = toValue(value)\n } else if (Array.isArray(previousValue)) {\n previousValue.push(toValue(value))\n } else {\n result[key] = [previousValue, toValue(value)]\n }\n }\n\n return result\n}\n"],"names":[],"mappings":";;AAwBO,SAAS,OACd,KACA,YAAoC,QAC5B;AACR,QAAM,SAAS,IAAI,gBAAA;AAEnB,aAAW,OAAO,KAAK;AACrB,UAAM,MAAM,IAAI,GAAG;AACnB,QAAI,QAAQ,QAAW;AACrB,aAAO,IAAI,KAAK,UAAU,GAAG,CAAC;AAAA,IAChC;AAAA,EACF;AAEA,SAAO,OAAO,SAAA;AAChB;AAUA,SAAS,QAAQ,KAAc;AAC7B,MAAI,CAAC,IAAK,QAAO;AAEjB,MAAI,QAAQ,QAAS,QAAO;AAC5B,MAAI,QAAQ,OAAQ,QAAO;AAC3B,SAAO,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;AACtD;AASO,SAAS,OAAO,KAAe;AACpC,QAAM,eAAe,IAAI,gBAAgB,GAAG;AAE5C,QAAM,SAAkC,uBAAO,OAAO,IAAI;AAE1D,aAAW,CAAC,KAAK,KAAK,KAAK,aAAa,WAAW;AACjD,UAAM,gBAAgB,OAAO,GAAG;AAChC,QAAI,iBAAiB,MAAM;AACzB,aAAO,GAAG,IAAI,QAAQ,KAAK;AAAA,IAC7B,WAAW,MAAM,QAAQ,aAAa,GAAG;AACvC,oBAAc,KAAK,QAAQ,KAAK,CAAC;AAAA,IACnC,OAAO;AACL,aAAO,GAAG,IAAI,CAAC,eAAe,QAAQ,KAAK,CAAC;AAAA,IAC9C;AAAA,EACF;AAEA,SAAO;AACT;;;"}
1
+ {"version":3,"file":"qss.cjs","names":[],"sources":["../../src/qss.ts"],"sourcesContent":["/**\n * Program is a reimplementation of the `qss` package:\n * Copyright (c) Luke Edwards luke.edwards05@gmail.com, MIT License\n * https://github.com/lukeed/qss/blob/master/license.md\n *\n * This reimplementation uses modern browser APIs\n * (namely URLSearchParams) and TypeScript while still\n * maintaining the original functionality and interface.\n *\n * Update: this implementation has also been mangled to\n * fit exactly our use-case (single value per key in encoding).\n */\n\n/**\n * Encodes an object into a query string.\n * @param obj - The object to encode into a query string.\n * @param stringify - An optional custom stringify function.\n * @returns The encoded query string.\n * @example\n * ```\n * // Example input: encode({ token: 'foo', key: 'value' })\n * // Expected output: \"token=foo&key=value\"\n * ```\n */\nexport function encode(\n obj: Record<string, any>,\n stringify: (value: any) => string = String,\n): string {\n const result = new URLSearchParams()\n\n for (const key in obj) {\n const val = obj[key]\n if (val !== undefined) {\n result.set(key, stringify(val))\n }\n }\n\n return result.toString()\n}\n\n/**\n * Converts a string value to its appropriate type (string, number, boolean).\n * @param mix - The string value to convert.\n * @returns The converted value.\n * @example\n * // Example input: toValue(\"123\")\n * // Expected output: 123\n */\nfunction toValue(str: unknown) {\n if (!str) return ''\n\n if (str === 'false') return false\n if (str === 'true') return true\n return +str * 0 === 0 && +str + '' === str ? +str : str\n}\n/**\n * Decodes a query string into an object.\n * @param str - The query string to decode.\n * @returns The decoded key-value pairs in an object format.\n * @example\n * // Example input: decode(\"token=foo&key=value\")\n * // Expected output: { \"token\": \"foo\", \"key\": \"value\" }\n */\nexport function decode(str: any): any {\n const searchParams = new URLSearchParams(str)\n\n const result: Record<string, unknown> = Object.create(null)\n\n for (const [key, value] of searchParams.entries()) {\n const previousValue = result[key]\n if (previousValue == null) {\n result[key] = toValue(value)\n } else if (Array.isArray(previousValue)) {\n previousValue.push(toValue(value))\n } else {\n result[key] = [previousValue, toValue(value)]\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,OACd,KACA,YAAoC,QAC5B;CACR,MAAM,SAAS,IAAI,iBAAiB;AAEpC,MAAK,MAAM,OAAO,KAAK;EACrB,MAAM,MAAM,IAAI;AAChB,MAAI,QAAQ,KAAA,EACV,QAAO,IAAI,KAAK,UAAU,IAAI,CAAC;;AAInC,QAAO,OAAO,UAAU;;;;;;;;;;AAW1B,SAAS,QAAQ,KAAc;AAC7B,KAAI,CAAC,IAAK,QAAO;AAEjB,KAAI,QAAQ,QAAS,QAAO;AAC5B,KAAI,QAAQ,OAAQ,QAAO;AAC3B,QAAO,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM;;;;;;;;;;AAUtD,SAAgB,OAAO,KAAe;CACpC,MAAM,eAAe,IAAI,gBAAgB,IAAI;CAE7C,MAAM,SAAkC,OAAO,OAAO,KAAK;AAE3D,MAAK,MAAM,CAAC,KAAK,UAAU,aAAa,SAAS,EAAE;EACjD,MAAM,gBAAgB,OAAO;AAC7B,MAAI,iBAAiB,KACnB,QAAO,OAAO,QAAQ,MAAM;WACnB,MAAM,QAAQ,cAAc,CACrC,eAAc,KAAK,QAAQ,MAAM,CAAC;MAElC,QAAO,OAAO,CAAC,eAAe,QAAQ,MAAM,CAAC;;AAIjD,QAAO"}
@@ -1,42 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
+ //#region src/redirect.ts
2
+ /**
3
+ * Create a redirect Response understood by TanStack Router.
4
+ *
5
+ * Use from route `loader`/`beforeLoad` or server functions to trigger a
6
+ * navigation. If `throw: true` is set, the redirect is thrown instead of
7
+ * returned. When an absolute `href` is supplied and `reloadDocument` is not
8
+ * set, a full-document navigation is inferred.
9
+ *
10
+ * @param opts Options for the redirect. Common fields:
11
+ * - `href`: absolute URL for external redirects; infers `reloadDocument`.
12
+ * - `statusCode`: HTTP status code to use (defaults to 307).
13
+ * - `headers`: additional headers to include on the Response.
14
+ * - Standard navigation options like `to`, `params`, `search`, `replace`,
15
+ * and `reloadDocument` for internal redirects.
16
+ * @returns A Response augmented with router navigation options.
17
+ * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction
18
+ */
3
19
  function redirect(opts) {
4
- opts.statusCode = opts.statusCode || opts.code || 307;
5
- if (!opts._builtLocation && !opts.reloadDocument && typeof opts.href === "string") {
6
- try {
7
- new URL(opts.href);
8
- opts.reloadDocument = true;
9
- } catch {
10
- }
11
- }
12
- const headers = new Headers(opts.headers);
13
- if (opts.href && headers.get("Location") === null) {
14
- headers.set("Location", opts.href);
15
- }
16
- const response = new Response(null, {
17
- status: opts.statusCode,
18
- headers
19
- });
20
- response.options = opts;
21
- if (opts.throw) {
22
- throw response;
23
- }
24
- return response;
20
+ opts.statusCode = opts.statusCode || opts.code || 307;
21
+ if (!opts._builtLocation && !opts.reloadDocument && typeof opts.href === "string") try {
22
+ new URL(opts.href);
23
+ opts.reloadDocument = true;
24
+ } catch {}
25
+ const headers = new Headers(opts.headers);
26
+ if (opts.href && headers.get("Location") === null) headers.set("Location", opts.href);
27
+ const response = new Response(null, {
28
+ status: opts.statusCode,
29
+ headers
30
+ });
31
+ response.options = opts;
32
+ if (opts.throw) throw response;
33
+ return response;
25
34
  }
35
+ /** Check whether a value is a TanStack Router redirect Response. */
36
+ /** Check whether a value is a TanStack Router redirect Response. */
26
37
  function isRedirect(obj) {
27
- return obj instanceof Response && !!obj.options;
38
+ return obj instanceof Response && !!obj.options;
28
39
  }
40
+ /** True if value is a redirect with a resolved `href` location. */
41
+ /** True if value is a redirect with a resolved `href` location. */
29
42
  function isResolvedRedirect(obj) {
30
- return isRedirect(obj) && !!obj.options.href;
43
+ return isRedirect(obj) && !!obj.options.href;
31
44
  }
45
+ /** Parse a serialized redirect object back into a redirect Response. */
46
+ /** Parse a serialized redirect object back into a redirect Response. */
32
47
  function parseRedirect(obj) {
33
- if (obj !== null && typeof obj === "object" && obj.isSerializedRedirect) {
34
- return redirect(obj);
35
- }
36
- return void 0;
48
+ if (obj !== null && typeof obj === "object" && obj.isSerializedRedirect) return redirect(obj);
37
49
  }
50
+ //#endregion
38
51
  exports.isRedirect = isRedirect;
39
52
  exports.isResolvedRedirect = isResolvedRedirect;
40
53
  exports.parseRedirect = parseRedirect;
41
54
  exports.redirect = redirect;
42
- //# sourceMappingURL=redirect.cjs.map
55
+
56
+ //# sourceMappingURL=redirect.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.cjs","sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"names":[],"mappings":";;AAkHO,SAAS,SAOd,MACmD;AACnD,OAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAElD,MACE,CAAC,KAAK,kBACN,CAAC,KAAK,kBACN,OAAO,KAAK,SAAS,UACrB;AACA,QAAI;AACF,UAAI,IAAI,KAAK,IAAI;AACjB,WAAK,iBAAiB;AAAA,IACxB,QAAQ;AAAA,IAAC;AAAA,EACX;AAEA,QAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;AACxC,MAAI,KAAK,QAAQ,QAAQ,IAAI,UAAU,MAAM,MAAM;AACjD,YAAQ,IAAI,YAAY,KAAK,IAAI;AAAA,EACnC;AAEA,QAAM,WAAW,IAAI,SAAS,MAAM;AAAA,IAClC,QAAQ,KAAK;AAAA,IACb;AAAA,EAAA,CACD;AAEC,WAA+D,UAC/D;AAEF,MAAI,KAAK,OAAO;AACd,UAAM;AAAA,EACR;AAEA,SAAO;AACT;AAIO,SAAS,WAAW,KAA8B;AACvD,SAAO,eAAe,YAAY,CAAC,CAAE,IAAY;AACnD;AAIO,SAAS,mBACd,KACoD;AACpD,SAAO,WAAW,GAAG,KAAK,CAAC,CAAC,IAAI,QAAQ;AAC1C;AAIO,SAAS,cAAc,KAAU;AACtC,MAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,sBAAsB;AACvE,WAAO,SAAS,GAAG;AAAA,EACrB;AAEA,SAAO;AACT;;;;;"}
1
+ {"version":3,"file":"redirect.cjs","names":[],"sources":["../../src/redirect.ts"],"sourcesContent":["import type { NavigateOptions } from './link'\nimport type { AnyRouter, RegisteredRouter } from './router'\nimport type { ParsedLocation } from './location'\n\nexport type AnyRedirect = Redirect<any, any, any, any, any>\n\n/**\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type Redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = Response & {\n options: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n }\n redirectHandled?: boolean\n}\n\nexport type RedirectOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '.',\n> = {\n href?: string\n /**\n * @deprecated Use `statusCode` instead\n **/\n code?: number\n /**\n * The HTTP status code to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)\n */\n statusCode?: number\n /**\n * If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)\n */\n throw?: any\n /**\n * The HTTP headers to use when redirecting.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)\n */\n headers?: HeadersInit\n /**\n * @internal\n * A **trusted** built location that can be used to redirect to.\n */\n _builtLocation?: ParsedLocation\n} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\nexport type ResolvedRedirect<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string = '',\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n\n/**\n * Options for route-bound redirect, where 'from' is automatically set.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport type RedirectOptionsRoute<\n TDefaultFrom extends string = string,\n TRouter extends AnyRouter = RegisteredRouter,\n TTo extends string | undefined = undefined,\n TMaskTo extends string = '',\n> = Omit<\n RedirectOptions<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>,\n 'from'\n>\n\n/**\n * A redirect function bound to a specific route, with 'from' pre-set to the route's fullPath.\n * This enables relative redirects like `Route.redirect({ to: './overview' })`.\n * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)\n */\nexport interface RedirectFnRoute<in out TDefaultFrom extends string = string> {\n <\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = undefined,\n const TMaskTo extends string = '',\n >(\n opts: RedirectOptionsRoute<TDefaultFrom, TRouter, TTo, TMaskTo>,\n ): Redirect<TRouter, TDefaultFrom, TTo, TDefaultFrom, TMaskTo>\n}\n\n/**\n * Create a redirect Response understood by TanStack Router.\n *\n * Use from route `loader`/`beforeLoad` or server functions to trigger a\n * navigation. If `throw: true` is set, the redirect is thrown instead of\n * returned. When an absolute `href` is supplied and `reloadDocument` is not\n * set, a full-document navigation is inferred.\n *\n * @param opts Options for the redirect. Common fields:\n * - `href`: absolute URL for external redirects; infers `reloadDocument`.\n * - `statusCode`: HTTP status code to use (defaults to 307).\n * - `headers`: additional headers to include on the Response.\n * - Standard navigation options like `to`, `params`, `search`, `replace`,\n * and `reloadDocument` for internal redirects.\n * @returns A Response augmented with router navigation options.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/redirectFunction\n */\nexport function redirect<\n TRouter extends AnyRouter = RegisteredRouter,\n const TTo extends string | undefined = '.',\n const TFrom extends string = string,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(\n opts: RedirectOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> {\n opts.statusCode = opts.statusCode || opts.code || 307\n\n if (\n !opts._builtLocation &&\n !opts.reloadDocument &&\n typeof opts.href === 'string'\n ) {\n try {\n new URL(opts.href)\n opts.reloadDocument = true\n } catch {}\n }\n\n const headers = new Headers(opts.headers)\n if (opts.href && headers.get('Location') === null) {\n headers.set('Location', opts.href)\n }\n\n const response = new Response(null, {\n status: opts.statusCode,\n headers,\n })\n\n ;(response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>).options =\n opts\n\n if (opts.throw) {\n throw response\n }\n\n return response as Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>\n}\n\n/** Check whether a value is a TanStack Router redirect Response. */\n/** Check whether a value is a TanStack Router redirect Response. */\nexport function isRedirect(obj: any): obj is AnyRedirect {\n return obj instanceof Response && !!(obj as any).options\n}\n\n/** True if value is a redirect with a resolved `href` location. */\n/** True if value is a redirect with a resolved `href` location. */\nexport function isResolvedRedirect(\n obj: any,\n): obj is AnyRedirect & { options: { href: string } } {\n return isRedirect(obj) && !!obj.options.href\n}\n\n/** Parse a serialized redirect object back into a redirect Response. */\n/** Parse a serialized redirect object back into a redirect Response. */\nexport function parseRedirect(obj: any) {\n if (obj !== null && typeof obj === 'object' && obj.isSerializedRedirect) {\n return redirect(obj)\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkHA,SAAgB,SAOd,MACmD;AACnD,MAAK,aAAa,KAAK,cAAc,KAAK,QAAQ;AAElD,KACE,CAAC,KAAK,kBACN,CAAC,KAAK,kBACN,OAAO,KAAK,SAAS,SAErB,KAAI;AACF,MAAI,IAAI,KAAK,KAAK;AAClB,OAAK,iBAAiB;SAChB;CAGV,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,KAAI,KAAK,QAAQ,QAAQ,IAAI,WAAW,KAAK,KAC3C,SAAQ,IAAI,YAAY,KAAK,KAAK;CAGpC,MAAM,WAAW,IAAI,SAAS,MAAM;EAClC,QAAQ,KAAK;EACb;EACD,CAAC;AAEA,UAA+D,UAC/D;AAEF,KAAI,KAAK,MACP,OAAM;AAGR,QAAO;;;;AAKT,SAAgB,WAAW,KAA8B;AACvD,QAAO,eAAe,YAAY,CAAC,CAAE,IAAY;;;;AAKnD,SAAgB,mBACd,KACoD;AACpD,QAAO,WAAW,IAAI,IAAI,CAAC,CAAC,IAAI,QAAQ;;;;AAK1C,SAAgB,cAAc,KAAU;AACtC,KAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,IAAI,qBACjD,QAAO,SAAS,IAAI"}
@@ -1,68 +1,68 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("./path.cjs");
1
+ const require_path = require("./path.cjs");
2
+ //#region src/rewrite.ts
3
+ /** Compose multiple rewrite pairs into a single in/out rewrite. */
4
+ /** Compose multiple rewrite pairs into a single in/out rewrite. */
4
5
  function composeRewrites(rewrites) {
5
- return {
6
- input: ({ url }) => {
7
- for (const rewrite of rewrites) {
8
- url = executeRewriteInput(rewrite, url);
9
- }
10
- return url;
11
- },
12
- output: ({ url }) => {
13
- for (let i = rewrites.length - 1; i >= 0; i--) {
14
- url = executeRewriteOutput(rewrites[i], url);
15
- }
16
- return url;
17
- }
18
- };
6
+ return {
7
+ input: ({ url }) => {
8
+ for (const rewrite of rewrites) url = executeRewriteInput(rewrite, url);
9
+ return url;
10
+ },
11
+ output: ({ url }) => {
12
+ for (let i = rewrites.length - 1; i >= 0; i--) url = executeRewriteOutput(rewrites[i], url);
13
+ return url;
14
+ }
15
+ };
19
16
  }
17
+ /** Create a rewrite pair that strips/adds a basepath on input/output. */
18
+ /** Create a rewrite pair that strips/adds a basepath on input/output. */
20
19
  function rewriteBasepath(opts) {
21
- const trimmedBasepath = path.trimPath(opts.basepath);
22
- const normalizedBasepath = `/${trimmedBasepath}`;
23
- const normalizedBasepathWithSlash = `${normalizedBasepath}/`;
24
- const checkBasepath = opts.caseSensitive ? normalizedBasepath : normalizedBasepath.toLowerCase();
25
- const checkBasepathWithSlash = opts.caseSensitive ? normalizedBasepathWithSlash : normalizedBasepathWithSlash.toLowerCase();
26
- return {
27
- input: ({ url }) => {
28
- const pathname = opts.caseSensitive ? url.pathname : url.pathname.toLowerCase();
29
- if (pathname === checkBasepath) {
30
- url.pathname = "/";
31
- } else if (pathname.startsWith(checkBasepathWithSlash)) {
32
- url.pathname = url.pathname.slice(normalizedBasepath.length);
33
- }
34
- return url;
35
- },
36
- output: ({ url }) => {
37
- url.pathname = path.joinPaths(["/", trimmedBasepath, url.pathname]);
38
- return url;
39
- }
40
- };
20
+ const trimmedBasepath = require_path.trimPath(opts.basepath);
21
+ const normalizedBasepath = `/${trimmedBasepath}`;
22
+ const normalizedBasepathWithSlash = `${normalizedBasepath}/`;
23
+ const checkBasepath = opts.caseSensitive ? normalizedBasepath : normalizedBasepath.toLowerCase();
24
+ const checkBasepathWithSlash = opts.caseSensitive ? normalizedBasepathWithSlash : normalizedBasepathWithSlash.toLowerCase();
25
+ return {
26
+ input: ({ url }) => {
27
+ const pathname = opts.caseSensitive ? url.pathname : url.pathname.toLowerCase();
28
+ if (pathname === checkBasepath) url.pathname = "/";
29
+ else if (pathname.startsWith(checkBasepathWithSlash)) url.pathname = url.pathname.slice(normalizedBasepath.length);
30
+ return url;
31
+ },
32
+ output: ({ url }) => {
33
+ url.pathname = require_path.joinPaths([
34
+ "/",
35
+ trimmedBasepath,
36
+ url.pathname
37
+ ]);
38
+ return url;
39
+ }
40
+ };
41
41
  }
42
+ /** Execute a location input rewrite if provided. */
43
+ /** Execute a location input rewrite if provided. */
42
44
  function executeRewriteInput(rewrite, url) {
43
- const res = rewrite?.input?.({ url });
44
- if (res) {
45
- if (typeof res === "string") {
46
- return new URL(res);
47
- } else if (res instanceof URL) {
48
- return res;
49
- }
50
- }
51
- return url;
45
+ const res = rewrite?.input?.({ url });
46
+ if (res) {
47
+ if (typeof res === "string") return new URL(res);
48
+ else if (res instanceof URL) return res;
49
+ }
50
+ return url;
52
51
  }
52
+ /** Execute a location output rewrite if provided. */
53
+ /** Execute a location output rewrite if provided. */
53
54
  function executeRewriteOutput(rewrite, url) {
54
- const res = rewrite?.output?.({ url });
55
- if (res) {
56
- if (typeof res === "string") {
57
- return new URL(res);
58
- } else if (res instanceof URL) {
59
- return res;
60
- }
61
- }
62
- return url;
55
+ const res = rewrite?.output?.({ url });
56
+ if (res) {
57
+ if (typeof res === "string") return new URL(res);
58
+ else if (res instanceof URL) return res;
59
+ }
60
+ return url;
63
61
  }
62
+ //#endregion
64
63
  exports.composeRewrites = composeRewrites;
65
64
  exports.executeRewriteInput = executeRewriteInput;
66
65
  exports.executeRewriteOutput = executeRewriteOutput;
67
66
  exports.rewriteBasepath = rewriteBasepath;
68
- //# sourceMappingURL=rewrite.cjs.map
67
+
68
+ //# sourceMappingURL=rewrite.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rewrite.cjs","sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const normalizedBasepathWithSlash = `${normalizedBasepath}/`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = opts.caseSensitive\n ? normalizedBasepathWithSlash\n : normalizedBasepathWithSlash.toLowerCase()\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Execute a location input rewrite if provided. */\n/** Execute a location input rewrite if provided. */\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\n/** Execute a location output rewrite if provided. */\n/** Execute a location output rewrite if provided. */\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"names":["trimPath","joinPaths"],"mappings":";;;AAKO,SAAS,gBAAgB,UAAkC;AAChE,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,iBAAW,WAAW,UAAU;AAC9B,cAAM,oBAAoB,SAAS,GAAG;AAAA,MACxC;AACA,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,eAAS,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;AAC7C,cAAM,qBAAqB,SAAS,CAAC,GAAG,GAAG;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAIO,SAAS,gBAAgB,MAG7B;AACD,QAAM,kBAAkBA,KAAAA,SAAS,KAAK,QAAQ;AAC9C,QAAM,qBAAqB,IAAI,eAAe;AAC9C,QAAM,8BAA8B,GAAG,kBAAkB;AACzD,QAAM,gBAAgB,KAAK,gBACvB,qBACA,mBAAmB,YAAA;AACvB,QAAM,yBAAyB,KAAK,gBAChC,8BACA,4BAA4B,YAAA;AAEhC,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,UAAU;AAClB,YAAM,WAAW,KAAK,gBAClB,IAAI,WACJ,IAAI,SAAS,YAAA;AAGjB,UAAI,aAAa,eAAe;AAC9B,YAAI,WAAW;AAAA,MACjB,WAAW,SAAS,WAAW,sBAAsB,GAAG;AAEtD,YAAI,WAAW,IAAI,SAAS,MAAM,mBAAmB,MAAM;AAAA,MAC7D;AACA,aAAO;AAAA,IACT;AAAA,IACA,QAAQ,CAAC,EAAE,UAAU;AACnB,UAAI,WAAWC,eAAU,CAAC,KAAK,iBAAiB,IAAI,QAAQ,CAAC;AAC7D,aAAO;AAAA,IACT;AAAA,EAAA;AAEJ;AAIO,SAAS,oBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,QAAQ,EAAE,KAAK;AACpC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAIO,SAAS,qBACd,SACA,KACK;AACL,QAAM,MAAM,SAAS,SAAS,EAAE,KAAK;AACrC,MAAI,KAAK;AACP,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB,WAAW,eAAe,KAAK;AAC7B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;;;;;"}
1
+ {"version":3,"file":"rewrite.cjs","names":[],"sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const normalizedBasepathWithSlash = `${normalizedBasepath}/`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = opts.caseSensitive\n ? normalizedBasepathWithSlash\n : normalizedBasepathWithSlash.toLowerCase()\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Execute a location input rewrite if provided. */\n/** Execute a location input rewrite if provided. */\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\n/** Execute a location output rewrite if provided. */\n/** Execute a location output rewrite if provided. */\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"mappings":";;;;AAKA,SAAgB,gBAAgB,UAAkC;AAChE,QAAO;EACL,QAAQ,EAAE,UAAU;AAClB,QAAK,MAAM,WAAW,SACpB,OAAM,oBAAoB,SAAS,IAAI;AAEzC,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,QAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,IACxC,OAAM,qBAAqB,SAAS,IAAI,IAAI;AAE9C,UAAO;;EAEV;;;;AAKH,SAAgB,gBAAgB,MAG7B;CACD,MAAM,kBAAkB,aAAA,SAAS,KAAK,SAAS;CAC/C,MAAM,qBAAqB,IAAI;CAC/B,MAAM,8BAA8B,GAAG,mBAAmB;CAC1D,MAAM,gBAAgB,KAAK,gBACvB,qBACA,mBAAmB,aAAa;CACpC,MAAM,yBAAyB,KAAK,gBAChC,8BACA,4BAA4B,aAAa;AAE7C,QAAO;EACL,QAAQ,EAAE,UAAU;GAClB,MAAM,WAAW,KAAK,gBAClB,IAAI,WACJ,IAAI,SAAS,aAAa;AAG9B,OAAI,aAAa,cACf,KAAI,WAAW;YACN,SAAS,WAAW,uBAAuB,CAEpD,KAAI,WAAW,IAAI,SAAS,MAAM,mBAAmB,OAAO;AAE9D,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,OAAI,WAAW,aAAA,UAAU;IAAC;IAAK;IAAiB,IAAI;IAAS,CAAC;AAC9D,UAAO;;EAEV;;;;AAKH,SAAgB,oBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,QAAQ,EAAE,KAAK,CAAC;AACrC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO;;;;AAKT,SAAgB,qBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,SAAS,EAAE,KAAK,CAAC;AACtC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO"}
package/dist/cjs/root.cjs CHANGED
@@ -1,5 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const rootRouteId = "__root__";
1
+ //#region src/root.ts
2
+ /** Stable identifier used for the root route in a route tree. */
3
+ var rootRouteId = "__root__";
4
+ //#endregion
4
5
  exports.rootRouteId = rootRouteId;
5
- //# sourceMappingURL=root.cjs.map
6
+
7
+ //# sourceMappingURL=root.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"root.cjs","sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"names":[],"mappings":";;AACO,MAAM,cAAc;;"}
1
+ {"version":3,"file":"root.cjs","names":[],"sources":["../../src/root.ts"],"sourcesContent":["/** Stable identifier used for the root route in a route tree. */\nexport const rootRouteId = '__root__'\nexport type RootRouteId = typeof rootRouteId\n"],"mappings":";;AACA,IAAa,cAAc"}
@@ -1,108 +1,99 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const invariant = require("tiny-invariant");
4
- const path = require("./path.cjs");
5
- const notFound = require("./not-found.cjs");
6
- const redirect = require("./redirect.cjs");
7
- const root = require("./root.cjs");
8
- class BaseRoute {
9
- constructor(options) {
10
- this.init = (opts) => {
11
- this.originalIndex = opts.originalIndex;
12
- const options2 = this.options;
13
- const isRoot = !options2?.path && !options2?.id;
14
- this.parentRoute = this.options.getParentRoute?.();
15
- if (isRoot) {
16
- this._path = root.rootRouteId;
17
- } else if (!this.parentRoute) {
18
- invariant(
19
- false,
20
- `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`
21
- );
22
- }
23
- let path$1 = isRoot ? root.rootRouteId : options2?.path;
24
- if (path$1 && path$1 !== "/") {
25
- path$1 = path.trimPathLeft(path$1);
26
- }
27
- const customId = options2?.id || path$1;
28
- let id = isRoot ? root.rootRouteId : path.joinPaths([
29
- this.parentRoute.id === root.rootRouteId ? "" : this.parentRoute.id,
30
- customId
31
- ]);
32
- if (path$1 === root.rootRouteId) {
33
- path$1 = "/";
34
- }
35
- if (id !== root.rootRouteId) {
36
- id = path.joinPaths(["/", id]);
37
- }
38
- const fullPath = id === root.rootRouteId ? "/" : path.joinPaths([this.parentRoute.fullPath, path$1]);
39
- this._path = path$1;
40
- this._id = id;
41
- this._fullPath = fullPath;
42
- this._to = path.trimPathRight(fullPath);
43
- };
44
- this.addChildren = (children) => {
45
- return this._addFileChildren(children);
46
- };
47
- this._addFileChildren = (children) => {
48
- if (Array.isArray(children)) {
49
- this.children = children;
50
- }
51
- if (typeof children === "object" && children !== null) {
52
- this.children = Object.values(children);
53
- }
54
- return this;
55
- };
56
- this._addFileTypes = () => {
57
- return this;
58
- };
59
- this.updateLoader = (options2) => {
60
- Object.assign(this.options, options2);
61
- return this;
62
- };
63
- this.update = (options2) => {
64
- Object.assign(this.options, options2);
65
- return this;
66
- };
67
- this.lazy = (lazyFn) => {
68
- this.lazyFn = lazyFn;
69
- return this;
70
- };
71
- this.redirect = (opts) => redirect.redirect({ from: this.fullPath, ...opts });
72
- this.options = options || {};
73
- this.isRoot = !options?.getParentRoute;
74
- if (options?.id && options?.path) {
75
- throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
76
- }
77
- }
78
- get to() {
79
- return this._to;
80
- }
81
- get id() {
82
- return this._id;
83
- }
84
- get path() {
85
- return this._path;
86
- }
87
- get fullPath() {
88
- return this._fullPath;
89
- }
90
- }
91
- class BaseRouteApi {
92
- constructor({ id }) {
93
- this.notFound = (opts) => {
94
- return notFound.notFound({ routeId: this.id, ...opts });
95
- };
96
- this.redirect = (opts) => redirect.redirect({ from: this.id, ...opts });
97
- this.id = id;
98
- }
99
- }
100
- class BaseRootRoute extends BaseRoute {
101
- constructor(options) {
102
- super(options);
103
- }
104
- }
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_path = require("./path.cjs");
3
+ const require_not_found = require("./not-found.cjs");
4
+ const require_root = require("./root.cjs");
5
+ const require_redirect = require("./redirect.cjs");
6
+ let tiny_invariant = require("tiny-invariant");
7
+ tiny_invariant = require_runtime.__toESM(tiny_invariant);
8
+ //#region src/route.ts
9
+ var BaseRoute = class {
10
+ get to() {
11
+ return this._to;
12
+ }
13
+ get id() {
14
+ return this._id;
15
+ }
16
+ get path() {
17
+ return this._path;
18
+ }
19
+ get fullPath() {
20
+ return this._fullPath;
21
+ }
22
+ constructor(options) {
23
+ this.init = (opts) => {
24
+ this.originalIndex = opts.originalIndex;
25
+ const options = this.options;
26
+ const isRoot = !options?.path && !options?.id;
27
+ this.parentRoute = this.options.getParentRoute?.();
28
+ if (isRoot) this._path = require_root.rootRouteId;
29
+ else if (!this.parentRoute) (0, tiny_invariant.default)(false, `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`);
30
+ let path = isRoot ? require_root.rootRouteId : options?.path;
31
+ if (path && path !== "/") path = require_path.trimPathLeft(path);
32
+ const customId = options?.id || path;
33
+ let id = isRoot ? require_root.rootRouteId : require_path.joinPaths([this.parentRoute.id === "__root__" ? "" : this.parentRoute.id, customId]);
34
+ if (path === "__root__") path = "/";
35
+ if (id !== "__root__") id = require_path.joinPaths(["/", id]);
36
+ const fullPath = id === "__root__" ? "/" : require_path.joinPaths([this.parentRoute.fullPath, path]);
37
+ this._path = path;
38
+ this._id = id;
39
+ this._fullPath = fullPath;
40
+ this._to = require_path.trimPathRight(fullPath);
41
+ };
42
+ this.addChildren = (children) => {
43
+ return this._addFileChildren(children);
44
+ };
45
+ this._addFileChildren = (children) => {
46
+ if (Array.isArray(children)) this.children = children;
47
+ if (typeof children === "object" && children !== null) this.children = Object.values(children);
48
+ return this;
49
+ };
50
+ this._addFileTypes = () => {
51
+ return this;
52
+ };
53
+ this.updateLoader = (options) => {
54
+ Object.assign(this.options, options);
55
+ return this;
56
+ };
57
+ this.update = (options) => {
58
+ Object.assign(this.options, options);
59
+ return this;
60
+ };
61
+ this.lazy = (lazyFn) => {
62
+ this.lazyFn = lazyFn;
63
+ return this;
64
+ };
65
+ this.redirect = (opts) => require_redirect.redirect({
66
+ from: this.fullPath,
67
+ ...opts
68
+ });
69
+ this.options = options || {};
70
+ this.isRoot = !options?.getParentRoute;
71
+ if (options?.id && options?.path) throw new Error(`Route cannot have both an 'id' and a 'path' option.`);
72
+ }
73
+ };
74
+ var BaseRouteApi = class {
75
+ constructor({ id }) {
76
+ this.notFound = (opts) => {
77
+ return require_not_found.notFound({
78
+ routeId: this.id,
79
+ ...opts
80
+ });
81
+ };
82
+ this.redirect = (opts) => require_redirect.redirect({
83
+ from: this.id,
84
+ ...opts
85
+ });
86
+ this.id = id;
87
+ }
88
+ };
89
+ var BaseRootRoute = class extends BaseRoute {
90
+ constructor(options) {
91
+ super(options);
92
+ }
93
+ };
94
+ //#endregion
105
95
  exports.BaseRootRoute = BaseRootRoute;
106
96
  exports.BaseRoute = BaseRoute;
107
97
  exports.BaseRouteApi = BaseRouteApi;
108
- //# sourceMappingURL=route.cjs.map
98
+
99
+ //# sourceMappingURL=route.cjs.map