react-router 7.16.0 → 8.0.0-pre.0

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 (369) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/development/dom-export.d.ts +6 -172
  3. package/dist/development/dom-export.js +12 -1007
  4. package/dist/development/index-react-server-client.d.ts +7 -4
  5. package/dist/development/index-react-server-client.js +8 -52
  6. package/dist/development/index-react-server.d.ts +1645 -1635
  7. package/dist/development/index-react-server.js +2880 -3642
  8. package/dist/development/index.d.ts +43 -1475
  9. package/dist/development/index.js +37 -2621
  10. package/dist/development/lib/actions.js +62 -0
  11. package/dist/development/lib/components.d.ts +1022 -0
  12. package/dist/development/lib/components.js +835 -0
  13. package/dist/development/lib/context.d.ts +83 -0
  14. package/dist/development/lib/context.js +41 -0
  15. package/dist/development/lib/dom/dom.d.ts +119 -0
  16. package/dist/development/lib/dom/dom.js +143 -0
  17. package/dist/development/lib/dom/lib.d.ts +2042 -0
  18. package/dist/development/lib/dom/lib.js +1259 -0
  19. package/dist/development/lib/dom/server.d.ts +138 -0
  20. package/dist/development/lib/dom/server.js +301 -0
  21. package/dist/development/lib/dom/ssr/components.d.ts +196 -0
  22. package/dist/development/lib/dom/ssr/components.js +579 -0
  23. package/dist/development/lib/dom/ssr/data.js +29 -0
  24. package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
  25. package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  26. package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
  27. package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
  28. package/dist/development/lib/dom/ssr/errors.js +36 -0
  29. package/dist/development/lib/dom/ssr/fallback.js +28 -0
  30. package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
  31. package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
  32. package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
  33. package/dist/development/lib/dom/ssr/hydration.js +29 -0
  34. package/dist/development/lib/dom/ssr/invariant.js +16 -0
  35. package/dist/development/lib/dom/ssr/links.js +170 -0
  36. package/dist/development/lib/dom/ssr/markup.js +24 -0
  37. package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
  38. package/dist/development/lib/dom/ssr/routeModules.js +31 -0
  39. package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  40. package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
  41. package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
  42. package/dist/development/lib/dom/ssr/routes.js +303 -0
  43. package/dist/development/lib/dom/ssr/server.d.ts +45 -0
  44. package/dist/development/lib/dom/ssr/server.js +68 -0
  45. package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
  46. package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
  47. package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
  48. package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
  49. package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
  50. package/dist/development/lib/dom-export/hydrated-router.js +153 -0
  51. package/dist/development/lib/errors.js +29 -0
  52. package/dist/development/lib/hooks.d.ts +947 -0
  53. package/dist/development/lib/hooks.js +1386 -0
  54. package/dist/development/lib/href.d.ts +20 -0
  55. package/dist/development/lib/href.js +50 -0
  56. package/dist/development/lib/router/history.d.ts +258 -0
  57. package/dist/development/lib/router/history.js +371 -0
  58. package/dist/development/lib/router/instrumentation.d.ts +86 -0
  59. package/dist/development/lib/router/instrumentation.js +213 -0
  60. package/dist/development/lib/router/links.d.ts +113 -0
  61. package/dist/development/lib/router/router.d.ts +663 -0
  62. package/dist/development/lib/router/router.js +2981 -0
  63. package/dist/development/lib/router/utils.d.ts +942 -0
  64. package/dist/development/lib/router/utils.js +791 -0
  65. package/dist/development/lib/rsc/browser.d.ts +137 -0
  66. package/dist/development/lib/rsc/browser.js +599 -0
  67. package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
  68. package/dist/development/lib/rsc/errorBoundaries.js +90 -0
  69. package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
  70. package/dist/development/lib/rsc/html-stream/browser.js +74 -0
  71. package/dist/development/lib/rsc/html-stream/server.js +78 -0
  72. package/dist/development/lib/rsc/route-modules.js +27 -0
  73. package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
  74. package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
  75. package/dist/development/lib/rsc/server.ssr.js +388 -0
  76. package/dist/development/lib/server-runtime/build.d.ts +66 -0
  77. package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
  78. package/dist/development/lib/server-runtime/cookies.js +139 -0
  79. package/dist/development/lib/server-runtime/crypto.js +43 -0
  80. package/dist/development/lib/server-runtime/data.d.ts +13 -0
  81. package/dist/development/lib/server-runtime/data.js +25 -0
  82. package/dist/development/lib/server-runtime/dev.d.ts +9 -0
  83. package/dist/development/lib/server-runtime/dev.js +26 -0
  84. package/dist/development/lib/server-runtime/entry.js +20 -0
  85. package/dist/development/lib/server-runtime/errors.js +95 -0
  86. package/dist/development/lib/server-runtime/headers.js +73 -0
  87. package/dist/development/lib/server-runtime/invariant.js +19 -0
  88. package/dist/development/lib/server-runtime/mode.d.ts +12 -0
  89. package/dist/development/lib/server-runtime/mode.js +25 -0
  90. package/dist/development/lib/server-runtime/routeMatching.js +28 -0
  91. package/dist/development/lib/server-runtime/routes.d.ts +13 -0
  92. package/dist/development/lib/server-runtime/routes.js +74 -0
  93. package/dist/development/lib/server-runtime/server.d.ts +10 -0
  94. package/dist/development/lib/server-runtime/server.js +351 -0
  95. package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
  96. package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  97. package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
  98. package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  99. package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
  100. package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
  101. package/dist/development/lib/server-runtime/sessions.js +98 -0
  102. package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
  103. package/dist/development/lib/server-runtime/single-fetch.js +215 -0
  104. package/dist/development/lib/server-runtime/urls.js +31 -0
  105. package/dist/development/lib/server-runtime/warnings.js +20 -0
  106. package/dist/development/lib/types/future.d.ts +9 -0
  107. package/dist/development/lib/types/internal.d.ts +26 -177
  108. package/dist/development/lib/types/internal.js +3 -2
  109. package/dist/{production/register-CNAx3TXj.d.ts → development/lib/types/register.d.ts} +9 -15
  110. package/dist/development/lib/types/route-data.d.ts +113 -0
  111. package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
  112. package/dist/development/lib/types/route-module.d.ts +19 -0
  113. package/dist/development/lib/types/serializes-to.d.ts +13 -0
  114. package/dist/development/lib/types/utils.d.ts +11 -0
  115. package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
  116. package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
  117. package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
  118. package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
  119. package/dist/production/dom-export.d.ts +6 -172
  120. package/dist/production/dom-export.js +12 -1007
  121. package/dist/production/index-react-server-client.d.ts +7 -4
  122. package/dist/production/index-react-server-client.js +8 -52
  123. package/dist/production/index-react-server.d.ts +1645 -1635
  124. package/dist/production/index-react-server.js +2871 -3642
  125. package/dist/production/index.d.ts +43 -1475
  126. package/dist/production/index.js +37 -2621
  127. package/dist/production/lib/actions.js +62 -0
  128. package/dist/production/lib/components.d.ts +1022 -0
  129. package/dist/production/lib/components.js +835 -0
  130. package/dist/production/lib/context.d.ts +83 -0
  131. package/dist/production/lib/context.js +41 -0
  132. package/dist/production/lib/dom/dom.d.ts +119 -0
  133. package/dist/production/lib/dom/dom.js +143 -0
  134. package/dist/production/lib/dom/lib.d.ts +2042 -0
  135. package/dist/production/lib/dom/lib.js +1259 -0
  136. package/dist/production/lib/dom/server.d.ts +138 -0
  137. package/dist/production/lib/dom/server.js +301 -0
  138. package/dist/production/lib/dom/ssr/components.d.ts +196 -0
  139. package/dist/production/lib/dom/ssr/components.js +579 -0
  140. package/dist/production/lib/dom/ssr/data.js +29 -0
  141. package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
  142. package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
  143. package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
  144. package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
  145. package/dist/production/lib/dom/ssr/errors.js +36 -0
  146. package/dist/production/lib/dom/ssr/fallback.js +21 -0
  147. package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
  148. package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
  149. package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
  150. package/dist/production/lib/dom/ssr/hydration.js +29 -0
  151. package/dist/production/lib/dom/ssr/invariant.js +16 -0
  152. package/dist/production/lib/dom/ssr/links.js +170 -0
  153. package/dist/production/lib/dom/ssr/markup.js +24 -0
  154. package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
  155. package/dist/production/lib/dom/ssr/routeModules.js +31 -0
  156. package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
  157. package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
  158. package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
  159. package/dist/production/lib/dom/ssr/routes.js +303 -0
  160. package/dist/production/lib/dom/ssr/server.d.ts +45 -0
  161. package/dist/production/lib/dom/ssr/server.js +68 -0
  162. package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
  163. package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
  164. package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
  165. package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
  166. package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
  167. package/dist/production/lib/dom-export/hydrated-router.js +153 -0
  168. package/dist/production/lib/errors.js +29 -0
  169. package/dist/production/lib/hooks.d.ts +947 -0
  170. package/dist/production/lib/hooks.js +1371 -0
  171. package/dist/production/lib/href.d.ts +20 -0
  172. package/dist/production/lib/href.js +50 -0
  173. package/dist/production/lib/router/history.d.ts +258 -0
  174. package/dist/production/lib/router/history.js +371 -0
  175. package/dist/production/lib/router/instrumentation.d.ts +86 -0
  176. package/dist/production/lib/router/instrumentation.js +213 -0
  177. package/dist/production/lib/router/links.d.ts +113 -0
  178. package/dist/production/lib/router/router.d.ts +663 -0
  179. package/dist/production/lib/router/router.js +2981 -0
  180. package/dist/production/lib/router/utils.d.ts +942 -0
  181. package/dist/production/lib/router/utils.js +782 -0
  182. package/dist/production/lib/rsc/browser.d.ts +137 -0
  183. package/dist/production/lib/rsc/browser.js +599 -0
  184. package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
  185. package/dist/production/lib/rsc/errorBoundaries.js +90 -0
  186. package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
  187. package/dist/production/lib/rsc/html-stream/browser.js +74 -0
  188. package/dist/production/lib/rsc/html-stream/server.js +78 -0
  189. package/dist/production/lib/rsc/route-modules.js +27 -0
  190. package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
  191. package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
  192. package/dist/production/lib/rsc/server.ssr.js +388 -0
  193. package/dist/production/lib/server-runtime/build.d.ts +66 -0
  194. package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
  195. package/dist/production/lib/server-runtime/cookies.js +139 -0
  196. package/dist/production/lib/server-runtime/crypto.js +43 -0
  197. package/dist/production/lib/server-runtime/data.d.ts +13 -0
  198. package/dist/production/lib/server-runtime/data.js +25 -0
  199. package/dist/production/lib/server-runtime/dev.d.ts +9 -0
  200. package/dist/production/lib/server-runtime/dev.js +26 -0
  201. package/dist/production/lib/server-runtime/entry.js +20 -0
  202. package/dist/production/lib/server-runtime/errors.js +95 -0
  203. package/dist/production/lib/server-runtime/headers.js +73 -0
  204. package/dist/production/lib/server-runtime/invariant.js +19 -0
  205. package/dist/production/lib/server-runtime/mode.d.ts +12 -0
  206. package/dist/production/lib/server-runtime/mode.js +25 -0
  207. package/dist/production/lib/server-runtime/routeMatching.js +28 -0
  208. package/dist/production/lib/server-runtime/routes.d.ts +13 -0
  209. package/dist/production/lib/server-runtime/routes.js +74 -0
  210. package/dist/production/lib/server-runtime/server.d.ts +10 -0
  211. package/dist/production/lib/server-runtime/server.js +351 -0
  212. package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
  213. package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
  214. package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
  215. package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
  216. package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
  217. package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
  218. package/dist/production/lib/server-runtime/sessions.js +98 -0
  219. package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
  220. package/dist/production/lib/server-runtime/single-fetch.js +215 -0
  221. package/dist/production/lib/server-runtime/urls.js +31 -0
  222. package/dist/production/lib/server-runtime/warnings.js +20 -0
  223. package/dist/production/lib/types/future.d.ts +9 -0
  224. package/dist/production/lib/types/internal.d.ts +26 -177
  225. package/dist/production/lib/types/internal.js +3 -2
  226. package/dist/{development/register-CNAx3TXj.d.ts → production/lib/types/register.d.ts} +9 -15
  227. package/dist/production/lib/types/route-data.d.ts +113 -0
  228. package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
  229. package/dist/production/lib/types/route-module.d.ts +19 -0
  230. package/dist/production/lib/types/serializes-to.d.ts +13 -0
  231. package/dist/production/lib/types/utils.d.ts +11 -0
  232. package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
  233. package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
  234. package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
  235. package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
  236. package/docs/explanation/backend-for-frontend.md +50 -0
  237. package/docs/explanation/code-splitting.md +77 -0
  238. package/docs/explanation/concurrency.md +135 -0
  239. package/docs/explanation/form-vs-fetcher.md +292 -0
  240. package/docs/explanation/hot-module-replacement.md +137 -0
  241. package/docs/explanation/hydration.md +14 -0
  242. package/docs/explanation/index-query-param.md +86 -0
  243. package/docs/explanation/index.md +4 -0
  244. package/docs/explanation/lazy-route-discovery.md +78 -0
  245. package/docs/explanation/location.md +6 -0
  246. package/docs/explanation/progressive-enhancement.md +150 -0
  247. package/docs/explanation/race-conditions.md +88 -0
  248. package/docs/explanation/react-transitions.md +160 -0
  249. package/docs/explanation/route-matching.md +7 -0
  250. package/docs/explanation/server-client-execution.md +4 -0
  251. package/docs/explanation/sessions-and-cookies.md +465 -0
  252. package/docs/explanation/special-files.md +16 -0
  253. package/docs/explanation/state-management.md +524 -0
  254. package/docs/explanation/styling.md +87 -0
  255. package/docs/explanation/type-safety.md +82 -0
  256. package/docs/how-to/accessibility.md +44 -0
  257. package/docs/how-to/client-data.md +199 -0
  258. package/docs/how-to/data-strategy.md +317 -0
  259. package/docs/how-to/error-boundary.md +231 -0
  260. package/docs/how-to/error-reporting.md +134 -0
  261. package/docs/how-to/fetchers.md +307 -0
  262. package/docs/how-to/file-route-conventions.md +410 -0
  263. package/docs/how-to/file-uploads.md +217 -0
  264. package/docs/how-to/form-validation.md +120 -0
  265. package/docs/how-to/headers.md +164 -0
  266. package/docs/how-to/index.md +4 -0
  267. package/docs/how-to/instrumentation.md +556 -0
  268. package/docs/how-to/meta.md +40 -0
  269. package/docs/how-to/middleware.md +728 -0
  270. package/docs/how-to/navigation-blocking.md +233 -0
  271. package/docs/how-to/optimize-revalidation.md +12 -0
  272. package/docs/how-to/pre-rendering.md +225 -0
  273. package/docs/how-to/presets.md +103 -0
  274. package/docs/how-to/react-server-components.md +899 -0
  275. package/docs/how-to/resource-routes.md +126 -0
  276. package/docs/how-to/route-module-type-safety.md +100 -0
  277. package/docs/how-to/search-params.md +4 -0
  278. package/docs/how-to/security.md +30 -0
  279. package/docs/how-to/server-bundles.md +66 -0
  280. package/docs/how-to/spa.md +120 -0
  281. package/docs/how-to/status.md +63 -0
  282. package/docs/how-to/suspense.md +132 -0
  283. package/docs/how-to/using-handle.md +117 -0
  284. package/docs/how-to/view-transitions.md +237 -0
  285. package/docs/how-to/webhook.md +50 -0
  286. package/docs/index.md +39 -0
  287. package/docs/start/data/actions.md +138 -0
  288. package/docs/start/data/custom.md +198 -0
  289. package/docs/start/data/data-loading.md +44 -0
  290. package/docs/start/data/index.md +4 -0
  291. package/docs/start/data/installation.md +52 -0
  292. package/docs/start/data/navigating.md +12 -0
  293. package/docs/start/data/pending-ui.md +12 -0
  294. package/docs/start/data/route-object.md +248 -0
  295. package/docs/start/data/routing.md +281 -0
  296. package/docs/start/data/testing.md +8 -0
  297. package/docs/start/declarative/index.md +4 -0
  298. package/docs/start/declarative/installation.md +43 -0
  299. package/docs/start/declarative/navigating.md +133 -0
  300. package/docs/start/declarative/routing.md +237 -0
  301. package/docs/start/declarative/url-values.md +65 -0
  302. package/docs/start/framework/actions.md +175 -0
  303. package/docs/start/framework/data-loading.md +201 -0
  304. package/docs/start/framework/deploying.md +96 -0
  305. package/docs/start/framework/index.md +4 -0
  306. package/docs/start/framework/installation.md +42 -0
  307. package/docs/start/framework/navigating.md +182 -0
  308. package/docs/start/framework/pending-ui.md +142 -0
  309. package/docs/start/framework/rendering.md +59 -0
  310. package/docs/start/framework/route-module.md +527 -0
  311. package/docs/start/framework/routing.md +362 -0
  312. package/docs/start/framework/testing.md +133 -0
  313. package/docs/start/index.md +4 -0
  314. package/docs/start/modes.md +201 -0
  315. package/docs/upgrading/component-routes.md +363 -0
  316. package/docs/upgrading/future.md +31 -0
  317. package/docs/upgrading/index.md +4 -0
  318. package/docs/upgrading/remix.md +403 -0
  319. package/docs/upgrading/router-provider.md +442 -0
  320. package/docs/upgrading/v6.md +379 -0
  321. package/package.json +44 -87
  322. package/dist/development/browser-D3uq9sI1.d.ts +0 -318
  323. package/dist/development/browser-nIQ4Nsyi.d.mts +0 -318
  324. package/dist/development/chunk-IBI7OMNB.js +0 -1363
  325. package/dist/development/chunk-QUQL4437.mjs +0 -11529
  326. package/dist/development/chunk-S54KXAEJ.mjs +0 -2585
  327. package/dist/development/chunk-SRID2YZ2.js +0 -10229
  328. package/dist/development/chunk-XEJDWL2B.js +0 -188
  329. package/dist/development/context-m8rizgnE.d.mts +0 -1771
  330. package/dist/development/data-D4xhSy90.d.ts +0 -1732
  331. package/dist/development/data-U8FS-wNn.d.mts +0 -1732
  332. package/dist/development/dom-export.d.mts +0 -172
  333. package/dist/development/dom-export.mjs +0 -1008
  334. package/dist/development/index-react-server-client-BLiUx67a.d.ts +0 -3655
  335. package/dist/development/index-react-server-client-CdKROblb.d.mts +0 -2600
  336. package/dist/development/index-react-server-client.d.mts +0 -4
  337. package/dist/development/index-react-server-client.mjs +0 -59
  338. package/dist/development/index-react-server.d.mts +0 -2703
  339. package/dist/development/index-react-server.mjs +0 -3780
  340. package/dist/development/index.d.mts +0 -1478
  341. package/dist/development/index.mjs +0 -277
  342. package/dist/development/instrumentation-1q4YhLGP.d.ts +0 -715
  343. package/dist/development/lib/types/internal.d.mts +0 -184
  344. package/dist/development/lib/types/internal.mjs +0 -10
  345. package/dist/development/register-CqK96Zfk.d.mts +0 -30
  346. package/dist/production/browser-D3uq9sI1.d.ts +0 -318
  347. package/dist/production/browser-nIQ4Nsyi.d.mts +0 -318
  348. package/dist/production/chunk-EAQNHM3N.js +0 -188
  349. package/dist/production/chunk-NALGHHKE.mjs +0 -2585
  350. package/dist/production/chunk-Q65P7S7Y.mjs +0 -11529
  351. package/dist/production/chunk-SKEDDLRM.js +0 -1363
  352. package/dist/production/chunk-Y7DNFQZP.js +0 -10229
  353. package/dist/production/context-m8rizgnE.d.mts +0 -1771
  354. package/dist/production/data-D4xhSy90.d.ts +0 -1732
  355. package/dist/production/data-U8FS-wNn.d.mts +0 -1732
  356. package/dist/production/dom-export.d.mts +0 -172
  357. package/dist/production/dom-export.mjs +0 -1008
  358. package/dist/production/index-react-server-client-BLiUx67a.d.ts +0 -3655
  359. package/dist/production/index-react-server-client-CdKROblb.d.mts +0 -2600
  360. package/dist/production/index-react-server-client.d.mts +0 -4
  361. package/dist/production/index-react-server-client.mjs +0 -59
  362. package/dist/production/index-react-server.d.mts +0 -2703
  363. package/dist/production/index-react-server.mjs +0 -3780
  364. package/dist/production/index.d.mts +0 -1478
  365. package/dist/production/index.mjs +0 -277
  366. package/dist/production/instrumentation-1q4YhLGP.d.ts +0 -715
  367. package/dist/production/lib/types/internal.d.mts +0 -184
  368. package/dist/production/lib/types/internal.mjs +0 -10
  369. package/dist/production/register-CqK96Zfk.d.mts +0 -30
@@ -0,0 +1,351 @@
1
+ /**
2
+ * react-router v8.0.0-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { ErrorResponseImpl, RouterContextProvider, defaultMapRouteProperties, isRouteErrorResponse, stripBasename } from "../router/utils.js";
12
+ import { instrumentHandler } from "../router/instrumentation.js";
13
+ import { createStaticHandler, getStaticContextFromError, isMutationMethod, isRedirectResponse, isResponse } from "../router/router.js";
14
+ import { getManifestPath } from "../dom/ssr/fog-of-war.js";
15
+ import { createEntryRouteModules } from "./entry.js";
16
+ import { isServerMode } from "./mode.js";
17
+ import { sanitizeErrors, serializeError, serializeErrors } from "./errors.js";
18
+ import { matchServerRoutes } from "./routeMatching.js";
19
+ import { getBuildTimeHeader, getDevServerHooks } from "./dev.js";
20
+ import { createStaticHandlerDataRoutes } from "./routes.js";
21
+ import { createServerHandoffString } from "./serverHandoff.js";
22
+ import { getDocumentHeaders } from "./headers.js";
23
+ import { throwIfPotentialCSRFAttack } from "../actions.js";
24
+ import { getNormalizedPath } from "./urls.js";
25
+ import { SERVER_NO_BODY_STATUS_CODES, encodeViaTurboStream, generateSingleFetchRedirectResponse, singleFetchAction, singleFetchLoaders } from "./single-fetch.js";
26
+ //#region lib/server-runtime/server.ts
27
+ function derive(build, mode) {
28
+ let dataRoutes = createStaticHandlerDataRoutes(build.routes);
29
+ let serverMode = isServerMode(mode) ? mode : "production";
30
+ let staticHandler = createStaticHandler(dataRoutes, {
31
+ basename: build.basename,
32
+ mapRouteProperties: defaultMapRouteProperties,
33
+ instrumentations: build.entry.module.instrumentations,
34
+ future: build.future
35
+ });
36
+ let errorHandler = build.entry.module.handleError || ((error, { request }) => {
37
+ if (serverMode !== "test" && !request.signal.aborted) console.error(isRouteErrorResponse(error) && error.error ? error.error : error);
38
+ });
39
+ let requestHandler = async (request, initialContext) => {
40
+ let params = {};
41
+ let loadContext;
42
+ let handleError = (error) => {
43
+ if (mode === "development") getDevServerHooks()?.processRequestError?.(error);
44
+ errorHandler(error, {
45
+ context: loadContext,
46
+ params,
47
+ request
48
+ });
49
+ };
50
+ if (initialContext && !(initialContext instanceof RouterContextProvider)) {
51
+ let error = /* @__PURE__ */ new Error("Invalid `context` value provided to `handleRequest`. You must return an instance of `RouterContextProvider` from your `getLoadContext` function.");
52
+ handleError(error);
53
+ return returnLastResortErrorResponse(error, serverMode);
54
+ }
55
+ loadContext = initialContext || new RouterContextProvider();
56
+ let requestUrl = new URL(request.url);
57
+ let normalizedPathname = getNormalizedPath(request, build.basename).pathname;
58
+ let isSpaMode = getBuildTimeHeader(request, "X-React-Router-SPA-Mode") === "yes";
59
+ if (!build.ssr) {
60
+ let decodedPath = decodeURI(normalizedPathname);
61
+ if (build.basename && build.basename !== "/") {
62
+ let strippedPath = stripBasename(decodedPath, build.basename);
63
+ if (strippedPath == null) {
64
+ errorHandler(new ErrorResponseImpl(404, "Not Found", `Refusing to prerender the \`${decodedPath}\` path because it does not start with the basename \`${build.basename}\``), {
65
+ context: loadContext,
66
+ params,
67
+ request
68
+ });
69
+ return new Response("Not Found", {
70
+ status: 404,
71
+ statusText: "Not Found"
72
+ });
73
+ }
74
+ decodedPath = strippedPath;
75
+ }
76
+ if (build.prerender.length === 0) isSpaMode = true;
77
+ else if (!build.prerender.includes(decodedPath) && !build.prerender.includes(decodedPath + "/")) if (requestUrl.pathname.endsWith(".data")) {
78
+ errorHandler(new ErrorResponseImpl(404, "Not Found", `Refusing to SSR the path \`${decodedPath}\` because \`ssr:false\` is set and the path is not included in the \`prerender\` config, so in production the path will be a 404.`), {
79
+ context: loadContext,
80
+ params,
81
+ request
82
+ });
83
+ return new Response("Not Found", {
84
+ status: 404,
85
+ statusText: "Not Found"
86
+ });
87
+ } else isSpaMode = true;
88
+ }
89
+ let manifestUrl = getManifestPath(build.routeDiscovery.manifestPath, build.basename);
90
+ if (build.routeDiscovery.mode === "lazy" && requestUrl.pathname === manifestUrl) try {
91
+ return await handleManifestRequest(build, staticHandler.dataRoutes, staticHandler._internalRouteBranches, requestUrl);
92
+ } catch (e) {
93
+ handleError(e);
94
+ return new Response("Unknown Server Error", { status: 500 });
95
+ }
96
+ let matches = matchServerRoutes(build.routes, staticHandler.dataRoutes, staticHandler._internalRouteBranches, normalizedPathname, build.basename);
97
+ if (matches && matches.length > 0) Object.assign(params, matches[0].params);
98
+ let response;
99
+ if (requestUrl.pathname.endsWith(".data")) {
100
+ response = await handleSingleFetchRequest(serverMode, build, staticHandler, request, loadContext, handleError);
101
+ if (isRedirectResponse(response)) response = generateSingleFetchRedirectResponse(response, request, build, serverMode);
102
+ if (build.entry.module.handleDataRequest) {
103
+ response = await build.entry.module.handleDataRequest(response, {
104
+ context: loadContext,
105
+ params: matches ? matches[0].params : {},
106
+ request
107
+ });
108
+ if (isRedirectResponse(response)) response = generateSingleFetchRedirectResponse(response, request, build, serverMode);
109
+ }
110
+ } else if (!isSpaMode && matches && matches[matches.length - 1].route.module.default == null && matches[matches.length - 1].route.module.ErrorBoundary == null) response = await handleResourceRequest(serverMode, build, staticHandler, matches.slice(-1)[0].route.id, request, loadContext, handleError);
111
+ else {
112
+ let { pathname } = requestUrl;
113
+ let criticalCss = void 0;
114
+ if (build.unstable_getCriticalCss) criticalCss = await build.unstable_getCriticalCss({ pathname });
115
+ else if (mode === "development" && getDevServerHooks()?.getCriticalCss) criticalCss = await getDevServerHooks()?.getCriticalCss?.(pathname);
116
+ response = await handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss);
117
+ }
118
+ if (request.method === "HEAD") return new Response(null, {
119
+ headers: response.headers,
120
+ status: response.status,
121
+ statusText: response.statusText
122
+ });
123
+ return response;
124
+ };
125
+ if (build.entry.module.instrumentations) requestHandler = instrumentHandler(requestHandler, build.entry.module.instrumentations.map((i) => i.handler).filter(Boolean));
126
+ return {
127
+ serverMode,
128
+ staticHandler,
129
+ errorHandler,
130
+ requestHandler
131
+ };
132
+ }
133
+ const createRequestHandler = (build, mode) => {
134
+ let _build;
135
+ let serverMode;
136
+ let staticHandler;
137
+ let errorHandler;
138
+ let _requestHandler;
139
+ return async function requestHandler(request, initialContext) {
140
+ _build = typeof build === "function" ? await build() : build;
141
+ if (typeof build === "function") {
142
+ let derived = derive(_build, mode);
143
+ serverMode = derived.serverMode;
144
+ staticHandler = derived.staticHandler;
145
+ errorHandler = derived.errorHandler;
146
+ _requestHandler = derived.requestHandler;
147
+ } else if (!serverMode || !staticHandler || !errorHandler || !_requestHandler) {
148
+ let derived = derive(_build, mode);
149
+ serverMode = derived.serverMode;
150
+ staticHandler = derived.staticHandler;
151
+ errorHandler = derived.errorHandler;
152
+ _requestHandler = derived.requestHandler;
153
+ }
154
+ return _requestHandler(request, initialContext);
155
+ };
156
+ };
157
+ async function handleManifestRequest(build, dataRoutes, branches, url) {
158
+ if (build.assets.version !== url.searchParams.get("version")) return new Response(null, {
159
+ status: 204,
160
+ headers: { "X-Remix-Reload-Document": "true" }
161
+ });
162
+ if (url.toString().length > 7680) return new Response(null, {
163
+ statusText: "Bad Request",
164
+ status: 400
165
+ });
166
+ let patches = {};
167
+ if (url.searchParams.has("paths")) {
168
+ let paths = /* @__PURE__ */ new Set();
169
+ (url.searchParams.get("paths") || "").split(",").filter(Boolean).forEach((path) => {
170
+ if (!path.startsWith("/")) path = `/${path}`;
171
+ let segments = path.split("/").slice(1);
172
+ segments.forEach((_, i) => {
173
+ let partialPath = segments.slice(0, i + 1).join("/");
174
+ paths.add(`/${partialPath}`);
175
+ });
176
+ });
177
+ for (let path of paths) {
178
+ let matches = matchServerRoutes(build.routes, dataRoutes, branches, path, build.basename);
179
+ if (matches) for (let match of matches) {
180
+ let routeId = match.route.id;
181
+ let route = build.assets.routes[routeId];
182
+ if (route) patches[routeId] = route;
183
+ }
184
+ }
185
+ return Response.json(patches, { headers: { "Cache-Control": "public, max-age=31536000, immutable" } });
186
+ }
187
+ return new Response("Invalid Request", { status: 400 });
188
+ }
189
+ async function handleSingleFetchRequest(serverMode, build, staticHandler, request, loadContext, handleError) {
190
+ return isMutationMethod(request.method) ? await singleFetchAction(build, serverMode, staticHandler, request, loadContext, handleError) : await singleFetchLoaders(build, serverMode, staticHandler, request, loadContext, handleError);
191
+ }
192
+ async function handleDocumentRequest(serverMode, build, staticHandler, request, loadContext, handleError, isSpaMode, criticalCss) {
193
+ try {
194
+ if (isMutationMethod(request.method)) try {
195
+ throwIfPotentialCSRFAttack(request.headers, Array.isArray(build.allowedActionOrigins) ? build.allowedActionOrigins : []);
196
+ } catch (e) {
197
+ handleError(e);
198
+ return new Response("Bad Request", { status: 400 });
199
+ }
200
+ let result = await staticHandler.query(request, {
201
+ requestContext: loadContext,
202
+ generateMiddlewareResponse: async (query) => {
203
+ try {
204
+ let innerResult = await query(request);
205
+ if (!isResponse(innerResult)) innerResult = await renderHtml(innerResult, isSpaMode);
206
+ return innerResult;
207
+ } catch (error) {
208
+ handleError(error);
209
+ return new Response(null, { status: 500 });
210
+ }
211
+ },
212
+ normalizePath: (r) => getNormalizedPath(r, build.basename)
213
+ });
214
+ if (!isResponse(result)) result = await renderHtml(result, isSpaMode);
215
+ return result;
216
+ } catch (error) {
217
+ handleError(error);
218
+ return new Response(null, { status: 500 });
219
+ }
220
+ async function renderHtml(context, isSpaMode) {
221
+ let headers = getDocumentHeaders(context, build);
222
+ if (SERVER_NO_BODY_STATUS_CODES.has(context.statusCode)) return new Response(null, {
223
+ status: context.statusCode,
224
+ headers
225
+ });
226
+ if (context.errors) {
227
+ Object.values(context.errors).forEach((err) => {
228
+ if (!isRouteErrorResponse(err) || err.error) handleError(err);
229
+ });
230
+ context.errors = sanitizeErrors(context.errors, serverMode);
231
+ }
232
+ let state = {
233
+ loaderData: context.loaderData,
234
+ actionData: context.actionData,
235
+ errors: serializeErrors(context.errors, serverMode)
236
+ };
237
+ let baseServerHandoff = {
238
+ basename: build.basename,
239
+ future: build.future,
240
+ routeDiscovery: build.routeDiscovery,
241
+ ssr: build.ssr,
242
+ isSpaMode
243
+ };
244
+ let entryContext = {
245
+ manifest: build.assets,
246
+ branches: staticHandler._internalRouteBranches,
247
+ routeModules: createEntryRouteModules(build.routes),
248
+ staticHandlerContext: context,
249
+ criticalCss,
250
+ serverHandoffString: createServerHandoffString({
251
+ ...baseServerHandoff,
252
+ criticalCss
253
+ }),
254
+ serverHandoffStream: encodeViaTurboStream(state, request.signal, build.entry.module.streamTimeout, serverMode),
255
+ renderMeta: {},
256
+ future: build.future,
257
+ ssr: build.ssr,
258
+ routeDiscovery: build.routeDiscovery,
259
+ isSpaMode,
260
+ serializeError: (err) => serializeError(err, serverMode)
261
+ };
262
+ let handleDocumentRequestFunction = build.entry.module.default;
263
+ try {
264
+ return await handleDocumentRequestFunction(request, context.statusCode, headers, entryContext, loadContext);
265
+ } catch (error) {
266
+ handleError(error);
267
+ let errorForSecondRender = error;
268
+ if (isResponse(error)) try {
269
+ let data = await unwrapResponse(error);
270
+ errorForSecondRender = new ErrorResponseImpl(error.status, error.statusText, data);
271
+ } catch (e) {}
272
+ context = getStaticContextFromError(staticHandler.dataRoutes, context, errorForSecondRender);
273
+ if (context.errors) context.errors = sanitizeErrors(context.errors, serverMode);
274
+ let state = {
275
+ loaderData: context.loaderData,
276
+ actionData: context.actionData,
277
+ errors: serializeErrors(context.errors, serverMode)
278
+ };
279
+ entryContext = {
280
+ ...entryContext,
281
+ staticHandlerContext: context,
282
+ serverHandoffString: createServerHandoffString(baseServerHandoff),
283
+ serverHandoffStream: encodeViaTurboStream(state, request.signal, build.entry.module.streamTimeout, serverMode),
284
+ renderMeta: {}
285
+ };
286
+ try {
287
+ return await handleDocumentRequestFunction(request, context.statusCode, headers, entryContext, loadContext);
288
+ } catch (error) {
289
+ handleError(error);
290
+ return returnLastResortErrorResponse(error, serverMode);
291
+ }
292
+ }
293
+ }
294
+ }
295
+ async function handleResourceRequest(serverMode, build, staticHandler, routeId, request, loadContext, handleError) {
296
+ try {
297
+ return handleQueryRouteResult(await staticHandler.queryRoute(request, {
298
+ routeId,
299
+ requestContext: loadContext,
300
+ generateMiddlewareResponse: async (queryRoute) => {
301
+ try {
302
+ return handleQueryRouteResult(await queryRoute(request));
303
+ } catch (error) {
304
+ return handleQueryRouteError(error);
305
+ }
306
+ },
307
+ normalizePath: (r) => getNormalizedPath(r, build.basename)
308
+ }));
309
+ } catch (error) {
310
+ return handleQueryRouteError(error);
311
+ }
312
+ function handleQueryRouteResult(result) {
313
+ if (isResponse(result)) return result;
314
+ if (typeof result === "string") return new Response(result);
315
+ return Response.json(result);
316
+ }
317
+ function handleQueryRouteError(error) {
318
+ if (isResponse(error)) return error;
319
+ if (isRouteErrorResponse(error)) {
320
+ handleError(error);
321
+ return errorResponseToJson(error, serverMode);
322
+ }
323
+ if (error instanceof Error && error.message === "Expected a response from queryRoute") {
324
+ let newError = /* @__PURE__ */ new Error("Expected a Response to be returned from resource route handler");
325
+ handleError(newError);
326
+ return returnLastResortErrorResponse(newError, serverMode);
327
+ }
328
+ handleError(error);
329
+ return returnLastResortErrorResponse(error, serverMode);
330
+ }
331
+ }
332
+ function errorResponseToJson(errorResponse, serverMode) {
333
+ return Response.json(serializeError(errorResponse.error || /* @__PURE__ */ new Error("Unexpected Server Error"), serverMode), {
334
+ status: errorResponse.status,
335
+ statusText: errorResponse.statusText
336
+ });
337
+ }
338
+ function returnLastResortErrorResponse(error, serverMode) {
339
+ let message = "Unexpected Server Error";
340
+ if (serverMode !== "production") message += `\n\n${String(error)}`;
341
+ return new Response(message, {
342
+ status: 500,
343
+ headers: { "Content-Type": "text/plain" }
344
+ });
345
+ }
346
+ function unwrapResponse(response) {
347
+ let contentType = response.headers.get("Content-Type");
348
+ return contentType && /\bapplication\/json\b/.test(contentType) ? response.body == null ? null : response.json() : response.text();
349
+ }
350
+ //#endregion
351
+ export { createRequestHandler };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * react-router v8.0.0-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { escapeHtml } from "../dom/ssr/markup.js";
12
+ //#region lib/server-runtime/serverHandoff.ts
13
+ function createServerHandoffString(serverHandoff) {
14
+ return escapeHtml(JSON.stringify(serverHandoff));
15
+ }
16
+ //#endregion
17
+ export { createServerHandoffString };
@@ -0,0 +1,25 @@
1
+
2
+ import { SessionData, SessionIdStorageStrategy, SessionStorage } from "../sessions.js";
3
+
4
+ //#region lib/server-runtime/sessions/cookieStorage.d.ts
5
+ interface CookieSessionStorageOptions {
6
+ /**
7
+ * The Cookie used to store the session data on the client, or options used
8
+ * to automatically create one.
9
+ */
10
+ cookie?: SessionIdStorageStrategy["cookie"];
11
+ }
12
+ /**
13
+ * Creates and returns a SessionStorage object that stores all session data
14
+ * directly in the session cookie itself.
15
+ *
16
+ * This has the advantage that no database or other backend services are
17
+ * needed, and can help to simplify some load-balanced scenarios. However, it
18
+ * also has the limitation that serialized session data may not exceed the
19
+ * browser's maximum cookie size. Trade-offs!
20
+ */
21
+ declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({
22
+ cookie: cookieArg
23
+ }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
24
+ //#endregion
25
+ export { createCookieSessionStorage };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * react-router v8.0.0-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { createCookie, isCookie } from "../cookies.js";
12
+ import { createSession, warnOnceAboutSigningSessionCookie } from "../sessions.js";
13
+ //#region lib/server-runtime/sessions/cookieStorage.ts
14
+ /**
15
+ * Creates and returns a SessionStorage object that stores all session data
16
+ * directly in the session cookie itself.
17
+ *
18
+ * This has the advantage that no database or other backend services are
19
+ * needed, and can help to simplify some load-balanced scenarios. However, it
20
+ * also has the limitation that serialized session data may not exceed the
21
+ * browser's maximum cookie size. Trade-offs!
22
+ */
23
+ function createCookieSessionStorage({ cookie: cookieArg } = {}) {
24
+ let cookie = isCookie(cookieArg) ? cookieArg : createCookie(cookieArg?.name || "__session", cookieArg);
25
+ warnOnceAboutSigningSessionCookie(cookie);
26
+ return {
27
+ async getSession(cookieHeader, options) {
28
+ return createSession(cookieHeader && await cookie.parse(cookieHeader, options) || {});
29
+ },
30
+ async commitSession(session, options) {
31
+ let serializedCookie = await cookie.serialize(session.data, options);
32
+ if (serializedCookie.length > 4096) throw new Error("Cookie length will exceed browser maximum. Length: " + serializedCookie.length);
33
+ return serializedCookie;
34
+ },
35
+ async destroySession(_session, options) {
36
+ return cookie.serialize("", {
37
+ ...options,
38
+ maxAge: void 0,
39
+ expires: /* @__PURE__ */ new Date(0)
40
+ });
41
+ }
42
+ };
43
+ }
44
+ //#endregion
45
+ export { createCookieSessionStorage };
@@ -0,0 +1,23 @@
1
+
2
+ import { SessionData, SessionIdStorageStrategy, SessionStorage } from "../sessions.js";
3
+
4
+ //#region lib/server-runtime/sessions/memoryStorage.d.ts
5
+ interface MemorySessionStorageOptions {
6
+ /**
7
+ * The Cookie used to store the session id on the client, or options used
8
+ * to automatically create one.
9
+ */
10
+ cookie?: SessionIdStorageStrategy["cookie"];
11
+ }
12
+ /**
13
+ * Creates and returns a simple in-memory SessionStorage object, mostly useful
14
+ * for testing and as a reference implementation.
15
+ *
16
+ * Note: This storage does not scale beyond a single process, so it is not
17
+ * suitable for most production scenarios.
18
+ */
19
+ declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({
20
+ cookie
21
+ }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
22
+ //#endregion
23
+ export { createMemorySessionStorage };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * react-router v8.0.0-pre.0
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { createSessionStorage } from "../sessions.js";
12
+ //#region lib/server-runtime/sessions/memoryStorage.ts
13
+ /**
14
+ * Creates and returns a simple in-memory SessionStorage object, mostly useful
15
+ * for testing and as a reference implementation.
16
+ *
17
+ * Note: This storage does not scale beyond a single process, so it is not
18
+ * suitable for most production scenarios.
19
+ */
20
+ function createMemorySessionStorage({ cookie } = {}) {
21
+ let map = /* @__PURE__ */ new Map();
22
+ return createSessionStorage({
23
+ cookie,
24
+ async createData(data, expires) {
25
+ let id = Math.random().toString(36).substring(2, 10);
26
+ map.set(id, {
27
+ data,
28
+ expires
29
+ });
30
+ return id;
31
+ },
32
+ async readData(id) {
33
+ if (map.has(id)) {
34
+ let { data, expires } = map.get(id);
35
+ if (!expires || expires > /* @__PURE__ */ new Date()) return data;
36
+ if (expires) map.delete(id);
37
+ }
38
+ return null;
39
+ },
40
+ async updateData(id, data, expires) {
41
+ map.set(id, {
42
+ data,
43
+ expires
44
+ });
45
+ },
46
+ async deleteData(id) {
47
+ map.delete(id);
48
+ }
49
+ });
50
+ }
51
+ //#endregion
52
+ export { createMemorySessionStorage };
@@ -0,0 +1,145 @@
1
+
2
+ import { Cookie, CookieOptions } from "./cookies.js";
3
+ import { CookieParseOptions, CookieSerializeOptions } from "cookie-es";
4
+
5
+ //#region lib/server-runtime/sessions.d.ts
6
+ /**
7
+ * An object of name/value pairs to be used in the session.
8
+ */
9
+ interface SessionData {
10
+ [name: string]: any;
11
+ }
12
+ /**
13
+ * Session persists data across HTTP requests.
14
+ *
15
+ * @see https://reactrouter.com/explanation/sessions-and-cookies#sessions
16
+ */
17
+ interface Session<Data = SessionData, FlashData = Data> {
18
+ /**
19
+ * A unique identifier for this session.
20
+ *
21
+ * Note: This will be the empty string for newly created sessions and
22
+ * sessions that are not backed by a database (i.e. cookie-based sessions).
23
+ */
24
+ readonly id: string;
25
+ /**
26
+ * The raw data contained in this session.
27
+ *
28
+ * This is useful mostly for SessionStorage internally to access the raw
29
+ * session data to persist.
30
+ */
31
+ readonly data: FlashSessionData<Data, FlashData>;
32
+ /**
33
+ * Returns `true` if the session has a value for the given `name`, `false`
34
+ * otherwise.
35
+ */
36
+ has(name: (keyof Data | keyof FlashData) & string): boolean;
37
+ /**
38
+ * Returns the value for the given `name` in this session.
39
+ */
40
+ get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
41
+ /**
42
+ * Sets a value in the session for the given `name`.
43
+ */
44
+ set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
45
+ /**
46
+ * Sets a value in the session that is only valid until the next `get()`.
47
+ * This can be useful for temporary values, like error messages.
48
+ */
49
+ flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
50
+ /**
51
+ * Removes a value from the session.
52
+ */
53
+ unset(name: keyof Data & string): void;
54
+ }
55
+ type FlashSessionData<Data, FlashData> = Partial<Data & { [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key] }>;
56
+ type FlashDataKey<Key extends string> = `__flash_${Key}__`;
57
+ type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
58
+ /**
59
+ * Creates a new Session object.
60
+ *
61
+ * Note: This function is typically not invoked directly by application code.
62
+ * Instead, use a `SessionStorage` object's `getSession` method.
63
+ */
64
+ declare const createSession: CreateSessionFunction;
65
+ type IsSessionFunction = (object: any) => object is Session;
66
+ /**
67
+ * Returns true if an object is a React Router session.
68
+ *
69
+ * @see https://reactrouter.com/api/utils/isSession
70
+ */
71
+ declare const isSession: IsSessionFunction;
72
+ /**
73
+ * SessionStorage stores session data between HTTP requests and knows how to
74
+ * parse and create cookies.
75
+ *
76
+ * A SessionStorage creates Session objects using a `Cookie` header as input.
77
+ * Then, later it generates the `Set-Cookie` header to be used in the response.
78
+ */
79
+ interface SessionStorage<Data = SessionData, FlashData = Data> {
80
+ /**
81
+ * Parses a Cookie header from a HTTP request and returns the associated
82
+ * Session. If there is no session associated with the cookie, this will
83
+ * return a new Session with no data.
84
+ */
85
+ getSession: (cookieHeader?: string | null, options?: CookieParseOptions) => Promise<Session<Data, FlashData>>;
86
+ /**
87
+ * Stores all data in the Session and returns the Set-Cookie header to be
88
+ * used in the HTTP response.
89
+ */
90
+ commitSession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
91
+ /**
92
+ * Deletes all data associated with the Session and returns the Set-Cookie
93
+ * header to be used in the HTTP response.
94
+ */
95
+ destroySession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
96
+ }
97
+ /**
98
+ * SessionIdStorageStrategy is designed to allow anyone to easily build their
99
+ * own SessionStorage using `createSessionStorage(strategy)`.
100
+ *
101
+ * This strategy describes a common scenario where the session id is stored in
102
+ * a cookie but the actual session data is stored elsewhere, usually in a
103
+ * database or on disk. A set of create, read, update, and delete operations
104
+ * are provided for managing the session data.
105
+ */
106
+ interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
107
+ /**
108
+ * The Cookie used to store the session id, or options used to automatically
109
+ * create one.
110
+ */
111
+ cookie?: Cookie | (CookieOptions & {
112
+ name?: string;
113
+ });
114
+ /**
115
+ * Creates a new record with the given data and returns the session id.
116
+ */
117
+ createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
118
+ /**
119
+ * Returns data for a given session id, or `null` if there isn't any.
120
+ */
121
+ readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
122
+ /**
123
+ * Updates data for the given session id.
124
+ */
125
+ updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
126
+ /**
127
+ * Deletes data for a given session id from the data store.
128
+ */
129
+ deleteData: (id: string) => Promise<void>;
130
+ }
131
+ /**
132
+ * Creates a SessionStorage object using a SessionIdStorageStrategy.
133
+ *
134
+ * Note: This is a low-level API that should only be used if none of the
135
+ * existing session storage options meet your requirements.
136
+ */
137
+ declare function createSessionStorage<Data = SessionData, FlashData = Data>({
138
+ cookie: cookieArg,
139
+ createData,
140
+ readData,
141
+ updateData,
142
+ deleteData
143
+ }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
144
+ //#endregion
145
+ export { FlashSessionData, IsSessionFunction, Session, SessionData, SessionIdStorageStrategy, SessionStorage, createSession, createSessionStorage, isSession };