react-router 7.15.1 → 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.
- package/CHANGELOG.md +18 -2
- package/dist/development/dom-export.d.ts +6 -172
- package/dist/development/dom-export.js +12 -1007
- package/dist/development/index-react-server-client.d.ts +7 -4
- package/dist/development/index-react-server-client.js +8 -52
- package/dist/development/index-react-server.d.ts +1645 -1635
- package/dist/development/index-react-server.js +2880 -3642
- package/dist/development/index.d.ts +43 -1469
- package/dist/development/index.js +37 -2621
- package/dist/development/lib/actions.js +62 -0
- package/dist/development/lib/components.d.ts +1022 -0
- package/dist/development/lib/components.js +835 -0
- package/dist/development/lib/context.d.ts +83 -0
- package/dist/development/lib/context.js +41 -0
- package/dist/development/lib/dom/dom.d.ts +119 -0
- package/dist/development/lib/dom/dom.js +143 -0
- package/dist/development/lib/dom/lib.d.ts +2042 -0
- package/dist/development/lib/dom/lib.js +1259 -0
- package/dist/development/lib/dom/server.d.ts +138 -0
- package/dist/development/lib/dom/server.js +301 -0
- package/dist/development/lib/dom/ssr/components.d.ts +196 -0
- package/dist/development/lib/dom/ssr/components.js +579 -0
- package/dist/development/lib/dom/ssr/data.js +29 -0
- package/dist/development/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/development/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/development/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/development/lib/dom/ssr/errors.js +36 -0
- package/dist/development/lib/dom/ssr/fallback.js +28 -0
- package/dist/development/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/development/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/development/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/development/lib/dom/ssr/hydration.js +29 -0
- package/dist/development/lib/dom/ssr/invariant.js +16 -0
- package/dist/development/lib/dom/ssr/links.js +170 -0
- package/dist/development/lib/dom/ssr/markup.js +24 -0
- package/dist/development/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/development/lib/dom/ssr/routeModules.js +31 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/development/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/development/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/development/lib/dom/ssr/routes.js +303 -0
- package/dist/development/lib/dom/ssr/server.d.ts +45 -0
- package/dist/development/lib/dom/ssr/server.js +68 -0
- package/dist/development/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/development/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/development/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/development/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/development/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/development/lib/dom-export/hydrated-router.js +153 -0
- package/dist/development/lib/errors.js +29 -0
- package/dist/development/lib/hooks.d.ts +947 -0
- package/dist/development/lib/hooks.js +1386 -0
- package/dist/development/lib/href.d.ts +20 -0
- package/dist/development/lib/href.js +50 -0
- package/dist/development/lib/router/history.d.ts +258 -0
- package/dist/development/lib/router/history.js +371 -0
- package/dist/development/lib/router/instrumentation.d.ts +86 -0
- package/dist/development/lib/router/instrumentation.js +213 -0
- package/dist/development/lib/router/links.d.ts +113 -0
- package/dist/development/lib/router/router.d.ts +663 -0
- package/dist/development/lib/router/router.js +2981 -0
- package/dist/development/lib/router/utils.d.ts +942 -0
- package/dist/development/lib/router/utils.js +791 -0
- package/dist/development/lib/rsc/browser.d.ts +137 -0
- package/dist/development/lib/rsc/browser.js +599 -0
- package/dist/development/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/development/lib/rsc/errorBoundaries.js +90 -0
- package/dist/development/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/development/lib/rsc/html-stream/browser.js +74 -0
- package/dist/development/lib/rsc/html-stream/server.js +78 -0
- package/dist/development/lib/rsc/route-modules.js +27 -0
- package/dist/development/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/development/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/development/lib/rsc/server.ssr.js +388 -0
- package/dist/development/lib/server-runtime/build.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/development/lib/server-runtime/cookies.js +139 -0
- package/dist/development/lib/server-runtime/crypto.js +43 -0
- package/dist/development/lib/server-runtime/data.d.ts +13 -0
- package/dist/development/lib/server-runtime/data.js +25 -0
- package/dist/development/lib/server-runtime/dev.d.ts +9 -0
- package/dist/development/lib/server-runtime/dev.js +26 -0
- package/dist/development/lib/server-runtime/entry.js +20 -0
- package/dist/development/lib/server-runtime/errors.js +95 -0
- package/dist/development/lib/server-runtime/headers.js +73 -0
- package/dist/development/lib/server-runtime/invariant.js +19 -0
- package/dist/development/lib/server-runtime/mode.d.ts +12 -0
- package/dist/development/lib/server-runtime/mode.js +25 -0
- package/dist/development/lib/server-runtime/routeMatching.js +28 -0
- package/dist/development/lib/server-runtime/routes.d.ts +13 -0
- package/dist/development/lib/server-runtime/routes.js +74 -0
- package/dist/development/lib/server-runtime/server.d.ts +10 -0
- package/dist/development/lib/server-runtime/server.js +351 -0
- package/dist/development/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/development/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/development/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/development/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/development/lib/server-runtime/sessions.js +98 -0
- package/dist/development/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/development/lib/server-runtime/single-fetch.js +215 -0
- package/dist/development/lib/server-runtime/urls.js +31 -0
- package/dist/development/lib/server-runtime/warnings.js +20 -0
- package/dist/development/lib/types/future.d.ts +9 -0
- package/dist/development/lib/types/internal.d.ts +26 -177
- package/dist/development/lib/types/internal.js +3 -2
- package/dist/{production/register-Bsscfj79.d.ts → development/lib/types/register.d.ts} +9 -15
- package/dist/development/lib/types/route-data.d.ts +113 -0
- package/dist/development/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/development/lib/types/route-module.d.ts +19 -0
- package/dist/development/lib/types/serializes-to.d.ts +13 -0
- package/dist/development/lib/types/utils.d.ts +11 -0
- package/dist/development/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/development/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/development/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/development/vendor/turbo-stream-v2/utils.js +47 -0
- package/dist/production/dom-export.d.ts +6 -172
- package/dist/production/dom-export.js +12 -1007
- package/dist/production/index-react-server-client.d.ts +7 -4
- package/dist/production/index-react-server-client.js +8 -52
- package/dist/production/index-react-server.d.ts +1645 -1635
- package/dist/production/index-react-server.js +2871 -3642
- package/dist/production/index.d.ts +43 -1469
- package/dist/production/index.js +37 -2621
- package/dist/production/lib/actions.js +62 -0
- package/dist/production/lib/components.d.ts +1022 -0
- package/dist/production/lib/components.js +835 -0
- package/dist/production/lib/context.d.ts +83 -0
- package/dist/production/lib/context.js +41 -0
- package/dist/production/lib/dom/dom.d.ts +119 -0
- package/dist/production/lib/dom/dom.js +143 -0
- package/dist/production/lib/dom/lib.d.ts +2042 -0
- package/dist/production/lib/dom/lib.js +1259 -0
- package/dist/production/lib/dom/server.d.ts +138 -0
- package/dist/production/lib/dom/server.js +301 -0
- package/dist/production/lib/dom/ssr/components.d.ts +196 -0
- package/dist/production/lib/dom/ssr/components.js +579 -0
- package/dist/production/lib/dom/ssr/data.js +29 -0
- package/dist/production/lib/dom/ssr/entry.d.ts +59 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.d.ts +27 -0
- package/dist/production/lib/dom/ssr/errorBoundaries.js +83 -0
- package/dist/production/lib/dom/ssr/errors.d.ts +7 -0
- package/dist/production/lib/dom/ssr/errors.js +36 -0
- package/dist/production/lib/dom/ssr/fallback.js +21 -0
- package/dist/production/lib/dom/ssr/fog-of-war.d.ts +12 -0
- package/dist/production/lib/dom/ssr/fog-of-war.js +170 -0
- package/dist/production/lib/dom/ssr/hydration.d.ts +32 -0
- package/dist/production/lib/dom/ssr/hydration.js +29 -0
- package/dist/production/lib/dom/ssr/invariant.js +16 -0
- package/dist/production/lib/dom/ssr/links.js +170 -0
- package/dist/production/lib/dom/ssr/markup.js +24 -0
- package/dist/production/lib/dom/ssr/routeModules.d.ts +206 -0
- package/dist/production/lib/dom/ssr/routeModules.js +31 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.d.ts +62 -0
- package/dist/production/lib/dom/ssr/routes-test-stub.js +108 -0
- package/dist/production/lib/dom/ssr/routes.d.ts +33 -0
- package/dist/production/lib/dom/ssr/routes.js +303 -0
- package/dist/production/lib/dom/ssr/server.d.ts +45 -0
- package/dist/production/lib/dom/ssr/server.js +68 -0
- package/dist/production/lib/dom/ssr/single-fetch.d.ts +14 -0
- package/dist/production/lib/dom/ssr/single-fetch.js +346 -0
- package/dist/production/lib/dom-export/dom-router-provider.d.ts +9 -0
- package/dist/production/lib/dom-export/dom-router-provider.js +22 -0
- package/dist/production/lib/dom-export/hydrated-router.d.ts +125 -0
- package/dist/production/lib/dom-export/hydrated-router.js +153 -0
- package/dist/production/lib/errors.js +29 -0
- package/dist/production/lib/hooks.d.ts +947 -0
- package/dist/production/lib/hooks.js +1371 -0
- package/dist/production/lib/href.d.ts +20 -0
- package/dist/production/lib/href.js +50 -0
- package/dist/production/lib/router/history.d.ts +258 -0
- package/dist/production/lib/router/history.js +371 -0
- package/dist/production/lib/router/instrumentation.d.ts +86 -0
- package/dist/production/lib/router/instrumentation.js +213 -0
- package/dist/production/lib/router/links.d.ts +113 -0
- package/dist/production/lib/router/router.d.ts +663 -0
- package/dist/production/lib/router/router.js +2981 -0
- package/dist/production/lib/router/utils.d.ts +942 -0
- package/dist/production/lib/router/utils.js +782 -0
- package/dist/production/lib/rsc/browser.d.ts +137 -0
- package/dist/production/lib/rsc/browser.js +599 -0
- package/dist/production/lib/rsc/errorBoundaries.d.ts +11 -0
- package/dist/production/lib/rsc/errorBoundaries.js +90 -0
- package/dist/production/lib/rsc/html-stream/browser.d.ts +48 -0
- package/dist/production/lib/rsc/html-stream/browser.js +74 -0
- package/dist/production/lib/rsc/html-stream/server.js +78 -0
- package/dist/production/lib/rsc/route-modules.js +27 -0
- package/dist/production/lib/rsc/server.rsc.d.ts +219 -0
- package/dist/production/lib/rsc/server.ssr.d.ts +129 -0
- package/dist/production/lib/rsc/server.ssr.js +388 -0
- package/dist/production/lib/server-runtime/build.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.d.ts +66 -0
- package/dist/production/lib/server-runtime/cookies.js +139 -0
- package/dist/production/lib/server-runtime/crypto.js +43 -0
- package/dist/production/lib/server-runtime/data.d.ts +13 -0
- package/dist/production/lib/server-runtime/data.js +25 -0
- package/dist/production/lib/server-runtime/dev.d.ts +9 -0
- package/dist/production/lib/server-runtime/dev.js +26 -0
- package/dist/production/lib/server-runtime/entry.js +20 -0
- package/dist/production/lib/server-runtime/errors.js +95 -0
- package/dist/production/lib/server-runtime/headers.js +73 -0
- package/dist/production/lib/server-runtime/invariant.js +19 -0
- package/dist/production/lib/server-runtime/mode.d.ts +12 -0
- package/dist/production/lib/server-runtime/mode.js +25 -0
- package/dist/production/lib/server-runtime/routeMatching.js +28 -0
- package/dist/production/lib/server-runtime/routes.d.ts +13 -0
- package/dist/production/lib/server-runtime/routes.js +74 -0
- package/dist/production/lib/server-runtime/server.d.ts +10 -0
- package/dist/production/lib/server-runtime/server.js +351 -0
- package/dist/production/lib/server-runtime/serverHandoff.js +17 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.d.ts +25 -0
- package/dist/production/lib/server-runtime/sessions/cookieStorage.js +45 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.d.ts +23 -0
- package/dist/production/lib/server-runtime/sessions/memoryStorage.js +52 -0
- package/dist/production/lib/server-runtime/sessions.d.ts +145 -0
- package/dist/production/lib/server-runtime/sessions.js +98 -0
- package/dist/production/lib/server-runtime/single-fetch.d.ts +7 -0
- package/dist/production/lib/server-runtime/single-fetch.js +215 -0
- package/dist/production/lib/server-runtime/urls.js +31 -0
- package/dist/production/lib/server-runtime/warnings.js +20 -0
- package/dist/production/lib/types/future.d.ts +9 -0
- package/dist/production/lib/types/internal.d.ts +26 -177
- package/dist/production/lib/types/internal.js +3 -2
- package/dist/{development/register-Bsscfj79.d.ts → production/lib/types/register.d.ts} +9 -15
- package/dist/production/lib/types/route-data.d.ts +113 -0
- package/dist/production/lib/types/route-module-annotations.d.ts +149 -0
- package/dist/production/lib/types/route-module.d.ts +19 -0
- package/dist/production/lib/types/serializes-to.d.ts +13 -0
- package/dist/production/lib/types/utils.d.ts +11 -0
- package/dist/production/vendor/turbo-stream-v2/flatten.js +159 -0
- package/dist/production/vendor/turbo-stream-v2/turbo-stream.js +178 -0
- package/dist/production/vendor/turbo-stream-v2/unflatten.js +198 -0
- package/dist/production/vendor/turbo-stream-v2/utils.js +47 -0
- package/docs/explanation/backend-for-frontend.md +50 -0
- package/docs/explanation/code-splitting.md +77 -0
- package/docs/explanation/concurrency.md +135 -0
- package/docs/explanation/form-vs-fetcher.md +292 -0
- package/docs/explanation/hot-module-replacement.md +137 -0
- package/docs/explanation/hydration.md +14 -0
- package/docs/explanation/index-query-param.md +86 -0
- package/docs/explanation/index.md +4 -0
- package/docs/explanation/lazy-route-discovery.md +78 -0
- package/docs/explanation/location.md +6 -0
- package/docs/explanation/progressive-enhancement.md +150 -0
- package/docs/explanation/race-conditions.md +88 -0
- package/docs/explanation/react-transitions.md +160 -0
- package/docs/explanation/route-matching.md +7 -0
- package/docs/explanation/server-client-execution.md +4 -0
- package/docs/explanation/sessions-and-cookies.md +465 -0
- package/docs/explanation/special-files.md +16 -0
- package/docs/explanation/state-management.md +524 -0
- package/docs/explanation/styling.md +87 -0
- package/docs/explanation/type-safety.md +82 -0
- package/docs/how-to/accessibility.md +44 -0
- package/docs/how-to/client-data.md +199 -0
- package/docs/how-to/data-strategy.md +317 -0
- package/docs/how-to/error-boundary.md +231 -0
- package/docs/how-to/error-reporting.md +134 -0
- package/docs/how-to/fetchers.md +307 -0
- package/docs/how-to/file-route-conventions.md +410 -0
- package/docs/how-to/file-uploads.md +217 -0
- package/docs/how-to/form-validation.md +120 -0
- package/docs/how-to/headers.md +164 -0
- package/docs/how-to/index.md +4 -0
- package/docs/how-to/instrumentation.md +556 -0
- package/docs/how-to/meta.md +40 -0
- package/docs/how-to/middleware.md +728 -0
- package/docs/how-to/navigation-blocking.md +233 -0
- package/docs/how-to/optimize-revalidation.md +12 -0
- package/docs/how-to/pre-rendering.md +225 -0
- package/docs/how-to/presets.md +103 -0
- package/docs/how-to/react-server-components.md +899 -0
- package/docs/how-to/resource-routes.md +126 -0
- package/docs/how-to/route-module-type-safety.md +100 -0
- package/docs/how-to/search-params.md +4 -0
- package/docs/how-to/security.md +30 -0
- package/docs/how-to/server-bundles.md +66 -0
- package/docs/how-to/spa.md +120 -0
- package/docs/how-to/status.md +63 -0
- package/docs/how-to/suspense.md +132 -0
- package/docs/how-to/using-handle.md +117 -0
- package/docs/how-to/view-transitions.md +237 -0
- package/docs/how-to/webhook.md +50 -0
- package/docs/index.md +39 -0
- package/docs/start/data/actions.md +138 -0
- package/docs/start/data/custom.md +198 -0
- package/docs/start/data/data-loading.md +44 -0
- package/docs/start/data/index.md +4 -0
- package/docs/start/data/installation.md +52 -0
- package/docs/start/data/navigating.md +12 -0
- package/docs/start/data/pending-ui.md +12 -0
- package/docs/start/data/route-object.md +248 -0
- package/docs/start/data/routing.md +281 -0
- package/docs/start/data/testing.md +8 -0
- package/docs/start/declarative/index.md +4 -0
- package/docs/start/declarative/installation.md +43 -0
- package/docs/start/declarative/navigating.md +133 -0
- package/docs/start/declarative/routing.md +237 -0
- package/docs/start/declarative/url-values.md +65 -0
- package/docs/start/framework/actions.md +175 -0
- package/docs/start/framework/data-loading.md +201 -0
- package/docs/start/framework/deploying.md +96 -0
- package/docs/start/framework/index.md +4 -0
- package/docs/start/framework/installation.md +42 -0
- package/docs/start/framework/navigating.md +182 -0
- package/docs/start/framework/pending-ui.md +142 -0
- package/docs/start/framework/rendering.md +59 -0
- package/docs/start/framework/route-module.md +527 -0
- package/docs/start/framework/routing.md +362 -0
- package/docs/start/framework/testing.md +133 -0
- package/docs/start/index.md +4 -0
- package/docs/start/modes.md +201 -0
- package/docs/upgrading/component-routes.md +363 -0
- package/docs/upgrading/future.md +31 -0
- package/docs/upgrading/index.md +4 -0
- package/docs/upgrading/remix.md +403 -0
- package/docs/upgrading/router-provider.md +442 -0
- package/docs/upgrading/v6.md +379 -0
- package/package.json +44 -87
- package/dist/development/browser-3AnU12UI.d.mts +0 -318
- package/dist/development/browser-BOdXz9dK.d.ts +0 -318
- package/dist/development/chunk-4N6VE7H7.mjs +0 -11528
- package/dist/development/chunk-4YRVXM2U.js +0 -188
- package/dist/development/chunk-66UKHEGQ.js +0 -1362
- package/dist/development/chunk-D6LUOGOQ.js +0 -10229
- package/dist/development/chunk-RJYABSBD.mjs +0 -2585
- package/dist/development/context-ByvtofY2.d.mts +0 -1771
- package/dist/development/data-BVUf681J.d.mts +0 -1732
- package/dist/development/data-BqZ2x964.d.ts +0 -1732
- package/dist/development/dom-export.d.mts +0 -172
- package/dist/development/dom-export.mjs +0 -1008
- package/dist/development/index-react-server-client-BS5F89FR.d.ts +0 -3655
- package/dist/development/index-react-server-client-DY04-103.d.mts +0 -2600
- package/dist/development/index-react-server-client.d.mts +0 -4
- package/dist/development/index-react-server-client.mjs +0 -59
- package/dist/development/index-react-server.d.mts +0 -2703
- package/dist/development/index-react-server.mjs +0 -3780
- package/dist/development/index.d.mts +0 -1472
- package/dist/development/index.mjs +0 -277
- package/dist/development/instrumentation-cRWWLfsU.d.ts +0 -715
- package/dist/development/lib/types/internal.d.mts +0 -184
- package/dist/development/lib/types/internal.mjs +0 -10
- package/dist/development/register-Df8okEea.d.mts +0 -30
- package/dist/production/browser-3AnU12UI.d.mts +0 -318
- package/dist/production/browser-BOdXz9dK.d.ts +0 -318
- package/dist/production/chunk-6S4627ZB.mjs +0 -2585
- package/dist/production/chunk-HUBUW7R3.js +0 -10229
- package/dist/production/chunk-JAKZPQZC.mjs +0 -11528
- package/dist/production/chunk-PNZCCTKT.js +0 -1362
- package/dist/production/chunk-Y6IFXO7V.js +0 -188
- package/dist/production/context-ByvtofY2.d.mts +0 -1771
- package/dist/production/data-BVUf681J.d.mts +0 -1732
- package/dist/production/data-BqZ2x964.d.ts +0 -1732
- package/dist/production/dom-export.d.mts +0 -172
- package/dist/production/dom-export.mjs +0 -1008
- package/dist/production/index-react-server-client-BS5F89FR.d.ts +0 -3655
- package/dist/production/index-react-server-client-DY04-103.d.mts +0 -2600
- package/dist/production/index-react-server-client.d.mts +0 -4
- package/dist/production/index-react-server-client.mjs +0 -59
- package/dist/production/index-react-server.d.mts +0 -2703
- package/dist/production/index-react-server.mjs +0 -3780
- package/dist/production/index.d.mts +0 -1472
- package/dist/production/index.mjs +0 -277
- package/dist/production/instrumentation-cRWWLfsU.d.ts +0 -715
- package/dist/production/lib/types/internal.d.mts +0 -184
- package/dist/production/lib/types/internal.mjs +0 -10
- package/dist/production/register-Df8okEea.d.mts +0 -30
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
import { DataWithResponseInit, RouterContextProvider } from "../router/utils.js";
|
|
3
|
+
import { Equal, Func, IsAny } from "./utils.js";
|
|
4
|
+
import { RouteModule } from "./route-module.js";
|
|
5
|
+
import { unstable_SerializesTo } from "./serializes-to.js";
|
|
6
|
+
import { Serializable } from "../server-runtime/single-fetch.js";
|
|
7
|
+
import { ClientActionFunctionArgs, ClientLoaderFunctionArgs } from "../dom/ssr/routeModules.js";
|
|
8
|
+
|
|
9
|
+
//#region lib/types/route-data.d.ts
|
|
10
|
+
type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends ((...args: any[]) => unknown) ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? { [K in keyof T]: Serialize<T[K]> } : undefined;
|
|
11
|
+
type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
|
|
12
|
+
type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
|
|
13
|
+
type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
|
|
14
|
+
type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
|
|
15
|
+
type ServerDataFrom<T> = ServerData<DataFrom<T>>;
|
|
16
|
+
type ClientDataFrom<T> = ClientData<DataFrom<T>>;
|
|
17
|
+
type ClientDataFunctionArgs<Params> = {
|
|
18
|
+
/**
|
|
19
|
+
* A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
|
|
20
|
+
*
|
|
21
|
+
* @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
|
|
22
|
+
**/
|
|
23
|
+
request: Request;
|
|
24
|
+
/**
|
|
25
|
+
* A URL instance representing the application location being navigated to or
|
|
26
|
+
* fetched.
|
|
27
|
+
*
|
|
28
|
+
* In Framework mode, this is a normalized URL with React-Router-specific
|
|
29
|
+
* implementation details removed (`.data` suffixes, `index`/`_routes` search
|
|
30
|
+
* params). For the raw incoming URL, use `request.url`.
|
|
31
|
+
*/
|
|
32
|
+
url: URL;
|
|
33
|
+
/**
|
|
34
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
35
|
+
* @example
|
|
36
|
+
* // app/routes.ts
|
|
37
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
38
|
+
*
|
|
39
|
+
* // app/team.tsx
|
|
40
|
+
* export function clientLoader({
|
|
41
|
+
* params,
|
|
42
|
+
* }: Route.ClientLoaderArgs) {
|
|
43
|
+
* params.teamId;
|
|
44
|
+
* // ^ string
|
|
45
|
+
* }
|
|
46
|
+
**/
|
|
47
|
+
params: Params;
|
|
48
|
+
/**
|
|
49
|
+
* Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
|
|
50
|
+
* Mostly useful as a identifier to aggregate on for logging/tracing/etc.
|
|
51
|
+
*/
|
|
52
|
+
pattern: string;
|
|
53
|
+
/**
|
|
54
|
+
* An instance of `RouterContextProvider` that can be used to access context
|
|
55
|
+
* values from your route middlewares. You may pass in initial context values
|
|
56
|
+
* in your `<HydratedRouter getContext>` prop.
|
|
57
|
+
*/
|
|
58
|
+
context: Readonly<RouterContextProvider>;
|
|
59
|
+
};
|
|
60
|
+
type ServerDataFunctionArgs<Params> = {
|
|
61
|
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */request: Request;
|
|
62
|
+
/**
|
|
63
|
+
* A URL instance representing the application location being navigated to or
|
|
64
|
+
* fetched.
|
|
65
|
+
*
|
|
66
|
+
* In Framework mode, this is a normalized URL with React-Router-specific
|
|
67
|
+
* implementation details removed (`.data` suffixes, `index`/`_routes` search
|
|
68
|
+
* params). For the raw incoming URL, use `request.url`.
|
|
69
|
+
*/
|
|
70
|
+
url: URL;
|
|
71
|
+
/**
|
|
72
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
73
|
+
* @example
|
|
74
|
+
* // app/routes.ts
|
|
75
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
76
|
+
*
|
|
77
|
+
* // app/team.tsx
|
|
78
|
+
* export function loader({
|
|
79
|
+
* params,
|
|
80
|
+
* }: Route.LoaderArgs) {
|
|
81
|
+
* params.teamId;
|
|
82
|
+
* // ^ string
|
|
83
|
+
* }
|
|
84
|
+
**/
|
|
85
|
+
params: Params;
|
|
86
|
+
/**
|
|
87
|
+
* Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
|
|
88
|
+
* Mostly useful as a identifier to aggregate on for logging/tracing/etc.
|
|
89
|
+
*/
|
|
90
|
+
pattern: string;
|
|
91
|
+
/**
|
|
92
|
+
* An instance of `RouterContextProvider` that can be used for type-safe
|
|
93
|
+
* access to context values set in your route middlewares. If you are using
|
|
94
|
+
* a custom server adapter, you may provide an initial set of context values
|
|
95
|
+
* from your `getLoadContext` function.
|
|
96
|
+
*/
|
|
97
|
+
context: Readonly<RouterContextProvider>;
|
|
98
|
+
};
|
|
99
|
+
type SerializeFrom<T> = T extends ((...args: infer Args) => unknown) ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
|
|
100
|
+
type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
|
|
101
|
+
type IsHydrate<ClientLoader> = ClientLoader extends {
|
|
102
|
+
hydrate: true;
|
|
103
|
+
} ? true : ClientLoader extends {
|
|
104
|
+
hydrate: false;
|
|
105
|
+
} ? false : false;
|
|
106
|
+
type GetLoaderData<T extends RouteModule> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
|
|
107
|
+
HydrateFallback: Func;
|
|
108
|
+
} ? true : false>;
|
|
109
|
+
type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [HasHydrateFallback, ClientLoaderHydrate] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [IsDefined<ClientLoaderData>, IsDefined<ServerLoaderData>] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
|
|
110
|
+
type GetActionData<T extends RouteModule> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
|
|
111
|
+
type _DataActionData<ServerActionData, ClientActionData> = Awaited<[IsDefined<ServerActionData>, IsDefined<ClientActionData>] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { ClientDataFunctionArgs, GetActionData, GetLoaderData, SerializeFrom, ServerDataFrom, ServerDataFunctionArgs };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
|
|
2
|
+
import { Location } from "../router/history.js";
|
|
3
|
+
import { DataStrategyResult, MiddlewareNextFunction } from "../router/utils.js";
|
|
4
|
+
import { LinkDescriptor } from "../router/links.js";
|
|
5
|
+
import { Func, Pretty } from "./utils.js";
|
|
6
|
+
import { RouteModule } from "./route-module.js";
|
|
7
|
+
import { ClientDataFunctionArgs, GetLoaderData, ServerDataFrom, ServerDataFunctionArgs } from "./route-data.js";
|
|
8
|
+
import { MetaDescriptor } from "../dom/ssr/routeModules.js";
|
|
9
|
+
|
|
10
|
+
//#region lib/types/route-module-annotations.d.ts
|
|
11
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
12
|
+
type Props = {
|
|
13
|
+
params: unknown;
|
|
14
|
+
loaderData: unknown;
|
|
15
|
+
actionData: unknown;
|
|
16
|
+
};
|
|
17
|
+
type RouteInfo = Props & {
|
|
18
|
+
module: RouteModule;
|
|
19
|
+
matches: Array<MatchInfo>;
|
|
20
|
+
};
|
|
21
|
+
type MatchInfo = {
|
|
22
|
+
id: string;
|
|
23
|
+
module: RouteModule;
|
|
24
|
+
};
|
|
25
|
+
type MetaMatch<T extends MatchInfo> = Pretty<{
|
|
26
|
+
id: T["id"];
|
|
27
|
+
params: Record<string, string | undefined>;
|
|
28
|
+
pathname: string;
|
|
29
|
+
meta: MetaDescriptor[];
|
|
30
|
+
loaderData: GetLoaderData<T["module"]>;
|
|
31
|
+
handle?: unknown;
|
|
32
|
+
error?: unknown;
|
|
33
|
+
}>;
|
|
34
|
+
type MetaMatches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [MetaMatch<F>, ...MetaMatches<R>] : Array<MetaMatch<MatchInfo> | undefined>;
|
|
35
|
+
type HasErrorBoundary<T extends RouteInfo> = T["module"] extends {
|
|
36
|
+
ErrorBoundary: Func;
|
|
37
|
+
} ? true : false;
|
|
38
|
+
type CreateMetaArgs<T extends RouteInfo> = {
|
|
39
|
+
/** This is the current router `Location` object. This is useful for generating tags for routes at specific paths or query parameters. */location: Location; /** {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route. */
|
|
40
|
+
params: T["params"]; /** The return value for this route's server loader function */
|
|
41
|
+
loaderData: T["loaderData"] | (HasErrorBoundary<T> extends true ? undefined : never); /** Thrown errors that trigger error boundaries will be passed to the meta function. This is useful for generating metadata for error pages. */
|
|
42
|
+
error?: unknown; /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
|
|
43
|
+
matches: MetaMatches<T["matches"]>;
|
|
44
|
+
};
|
|
45
|
+
type MetaDescriptors = MetaDescriptor[];
|
|
46
|
+
type HeadersArgs = {
|
|
47
|
+
loaderHeaders: Headers;
|
|
48
|
+
parentHeaders: Headers;
|
|
49
|
+
actionHeaders: Headers;
|
|
50
|
+
errorHeaders: Headers | undefined;
|
|
51
|
+
};
|
|
52
|
+
type CreateServerMiddlewareFunction<T extends RouteInfo> = (args: ServerDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Response>) => MaybePromise<Response | void>;
|
|
53
|
+
type CreateClientMiddlewareFunction<T extends RouteInfo> = (args: ClientDataFunctionArgs<T["params"]>, next: MiddlewareNextFunction<Record<string, DataStrategyResult>>) => MaybePromise<Record<string, DataStrategyResult> | void>;
|
|
54
|
+
type CreateServerLoaderArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
|
|
55
|
+
type CreateClientLoaderArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
|
|
56
|
+
/** This is an asynchronous function to get the data from the server loader for this route. On client-side navigations, this will make a {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server loader. If you opt-into running your clientLoader on hydration, then this function will return the data that was already loaded on the server (via Promise.resolve). */serverLoader: () => Promise<ServerDataFrom<T["module"]["loader"]>>;
|
|
57
|
+
};
|
|
58
|
+
type CreateServerActionArgs<T extends RouteInfo> = ServerDataFunctionArgs<T["params"]>;
|
|
59
|
+
type CreateClientActionArgs<T extends RouteInfo> = ClientDataFunctionArgs<T["params"]> & {
|
|
60
|
+
/** This is an asynchronous function that makes the {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API fetch} call to the React Router server action for this route. */serverAction: () => Promise<ServerDataFrom<T["module"]["action"]>>;
|
|
61
|
+
};
|
|
62
|
+
type CreateHydrateFallbackProps<T extends RouteInfo, RSCEnabled extends boolean> = {
|
|
63
|
+
params: T["params"];
|
|
64
|
+
} & (RSCEnabled extends true ? {
|
|
65
|
+
/** The data returned from the `loader` */loaderData?: ServerDataFrom<T["module"]["loader"]>; /** The data returned from the `action` following an action submission. */
|
|
66
|
+
actionData?: ServerDataFrom<T["module"]["action"]>;
|
|
67
|
+
} : {
|
|
68
|
+
/** The data returned from the `loader` or `clientLoader` */loaderData?: T["loaderData"]; /** The data returned from the `action` or `clientAction` following an action submission. */
|
|
69
|
+
actionData?: T["actionData"];
|
|
70
|
+
});
|
|
71
|
+
type Match<T extends MatchInfo> = Pretty<{
|
|
72
|
+
id: T["id"];
|
|
73
|
+
params: Record<string, string | undefined>;
|
|
74
|
+
pathname: string;
|
|
75
|
+
loaderData: GetLoaderData<T["module"]>;
|
|
76
|
+
handle: unknown;
|
|
77
|
+
}>;
|
|
78
|
+
type Matches<T extends Array<MatchInfo>> = T extends [infer F extends MatchInfo, ...infer R extends Array<MatchInfo>] ? [Match<F>, ...Matches<R>] : Array<Match<MatchInfo> | undefined>;
|
|
79
|
+
type CreateComponentProps<T extends RouteInfo, RSCEnabled extends boolean> = {
|
|
80
|
+
/**
|
|
81
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
82
|
+
* @example
|
|
83
|
+
* // app/routes.ts
|
|
84
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
85
|
+
*
|
|
86
|
+
* // app/team.tsx
|
|
87
|
+
* export default function Component({
|
|
88
|
+
* params,
|
|
89
|
+
* }: Route.ComponentProps) {
|
|
90
|
+
* params.teamId;
|
|
91
|
+
* // ^ string
|
|
92
|
+
* }
|
|
93
|
+
**/
|
|
94
|
+
params: T["params"]; /** An array of the current {@link https://api.reactrouter.com/v7/interfaces/react-router.UIMatch.html route matches}, including parent route matches. */
|
|
95
|
+
matches: Matches<T["matches"]>;
|
|
96
|
+
} & (RSCEnabled extends true ? {
|
|
97
|
+
/** The data returned from the `loader` */loaderData: ServerDataFrom<T["module"]["loader"]>; /** The data returned from the `action` following an action submission. */
|
|
98
|
+
actionData?: ServerDataFrom<T["module"]["action"]>;
|
|
99
|
+
} : {
|
|
100
|
+
/** The data returned from the `loader` or `clientLoader` */loaderData: T["loaderData"]; /** The data returned from the `action` or `clientAction` following an action submission. */
|
|
101
|
+
actionData?: T["actionData"];
|
|
102
|
+
});
|
|
103
|
+
type CreateErrorBoundaryProps<T extends RouteInfo, RSCEnabled extends boolean> = {
|
|
104
|
+
/**
|
|
105
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
106
|
+
* @example
|
|
107
|
+
* // app/routes.ts
|
|
108
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
109
|
+
*
|
|
110
|
+
* // app/team.tsx
|
|
111
|
+
* export function ErrorBoundary({
|
|
112
|
+
* params,
|
|
113
|
+
* }: Route.ErrorBoundaryProps) {
|
|
114
|
+
* params.teamId;
|
|
115
|
+
* // ^ string
|
|
116
|
+
* }
|
|
117
|
+
**/
|
|
118
|
+
params: T["params"];
|
|
119
|
+
error: unknown;
|
|
120
|
+
} & (RSCEnabled extends true ? {
|
|
121
|
+
/** The data returned from the `loader` */loaderData?: ServerDataFrom<T["module"]["loader"]>; /** The data returned from the `action` following an action submission. */
|
|
122
|
+
actionData?: ServerDataFrom<T["module"]["action"]>;
|
|
123
|
+
} : {
|
|
124
|
+
/** The data returned from the `loader` or `clientLoader` */loaderData?: T["loaderData"]; /** The data returned from the `action` or `clientAction` following an action submission. */
|
|
125
|
+
actionData?: T["actionData"];
|
|
126
|
+
});
|
|
127
|
+
type GetAnnotations<Info extends RouteInfo> = {
|
|
128
|
+
LinkDescriptors: LinkDescriptor[];
|
|
129
|
+
LinksFunction: () => LinkDescriptor[];
|
|
130
|
+
MetaArgs: CreateMetaArgs<Info>;
|
|
131
|
+
MetaDescriptors: MetaDescriptors;
|
|
132
|
+
MetaFunction: (args: CreateMetaArgs<Info>) => MetaDescriptors;
|
|
133
|
+
HeadersArgs: HeadersArgs;
|
|
134
|
+
HeadersFunction: (args: HeadersArgs) => Headers | HeadersInit;
|
|
135
|
+
MiddlewareFunction: CreateServerMiddlewareFunction<Info>;
|
|
136
|
+
ClientMiddlewareFunction: CreateClientMiddlewareFunction<Info>;
|
|
137
|
+
LoaderArgs: CreateServerLoaderArgs<Info>;
|
|
138
|
+
ClientLoaderArgs: CreateClientLoaderArgs<Info>;
|
|
139
|
+
ActionArgs: CreateServerActionArgs<Info>;
|
|
140
|
+
ClientActionArgs: CreateClientActionArgs<Info>;
|
|
141
|
+
HydrateFallbackProps: CreateHydrateFallbackProps<Info, false>;
|
|
142
|
+
ServerHydrateFallbackProps: CreateHydrateFallbackProps<Info, true>;
|
|
143
|
+
ComponentProps: CreateComponentProps<Info, false>;
|
|
144
|
+
ServerComponentProps: CreateComponentProps<Info, true>;
|
|
145
|
+
ErrorBoundaryProps: CreateErrorBoundaryProps<Info, false>;
|
|
146
|
+
ServerErrorBoundaryProps: CreateErrorBoundaryProps<Info, true>;
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
export { GetAnnotations };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { Func } from "./utils.js";
|
|
3
|
+
|
|
4
|
+
//#region lib/types/route-module.d.ts
|
|
5
|
+
type RouteModule = {
|
|
6
|
+
meta?: Func;
|
|
7
|
+
links?: Func;
|
|
8
|
+
headers?: Func;
|
|
9
|
+
loader?: Func;
|
|
10
|
+
clientLoader?: Func;
|
|
11
|
+
action?: Func;
|
|
12
|
+
clientAction?: Func;
|
|
13
|
+
HydrateFallback?: Func;
|
|
14
|
+
default?: Func;
|
|
15
|
+
ErrorBoundary?: Func;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { RouteModule };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region lib/types/serializes-to.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A brand that can be applied to a type to indicate that it will serialize
|
|
5
|
+
* to a specific type when transported to the client from a loader.
|
|
6
|
+
* Only use this if you have additional serialization/deserialization logic
|
|
7
|
+
* in your application.
|
|
8
|
+
*/
|
|
9
|
+
type unstable_SerializesTo<T> = {
|
|
10
|
+
unstable__ReactRouter_SerializesTo: [T];
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { unstable_SerializesTo };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
//#region lib/types/utils.d.ts
|
|
3
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
4
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
5
|
+
type Func = (...args: any[]) => unknown;
|
|
6
|
+
type Pretty<T> = { [K in keyof T]: T[K] } & {};
|
|
7
|
+
type Normalize<T> = _Normalize<UnionKeys<T>, T>;
|
|
8
|
+
type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{ [K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never } & { [K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never } & { [K in Key as K extends keyof U ? never : K]?: undefined }> : never;
|
|
9
|
+
type UnionKeys<T> = T extends any ? keyof T : never;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Equal, Func, IsAny, Normalize, Pretty };
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
//#region vendor/turbo-stream-v2/flatten.ts
|
|
12
|
+
const TIME_LIMIT_MS = 1;
|
|
13
|
+
const getNow = () => Date.now();
|
|
14
|
+
const yieldToMain = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
15
|
+
async function flatten(input) {
|
|
16
|
+
const { indices } = this;
|
|
17
|
+
const existing = indices.get(input);
|
|
18
|
+
if (existing) return [existing];
|
|
19
|
+
if (input === void 0) return -7;
|
|
20
|
+
if (input === null) return -5;
|
|
21
|
+
if (Number.isNaN(input)) return -2;
|
|
22
|
+
if (input === Number.POSITIVE_INFINITY) return -6;
|
|
23
|
+
if (input === Number.NEGATIVE_INFINITY) return -3;
|
|
24
|
+
if (input === 0 && 1 / input < 0) return -4;
|
|
25
|
+
const index = this.index++;
|
|
26
|
+
indices.set(input, index);
|
|
27
|
+
const stack = [[input, index]];
|
|
28
|
+
await stringify.call(this, stack);
|
|
29
|
+
return index;
|
|
30
|
+
}
|
|
31
|
+
async function stringify(stack) {
|
|
32
|
+
const { deferred, indices, plugins, postPlugins } = this;
|
|
33
|
+
const str = this.stringified;
|
|
34
|
+
let lastYieldTime = getNow();
|
|
35
|
+
const flattenValue = (value) => {
|
|
36
|
+
const existing = indices.get(value);
|
|
37
|
+
if (existing) return [existing];
|
|
38
|
+
if (value === void 0) return -7;
|
|
39
|
+
if (value === null) return -5;
|
|
40
|
+
if (Number.isNaN(value)) return -2;
|
|
41
|
+
if (value === Number.POSITIVE_INFINITY) return -6;
|
|
42
|
+
if (value === Number.NEGATIVE_INFINITY) return -3;
|
|
43
|
+
if (value === 0 && 1 / value < 0) return -4;
|
|
44
|
+
const index = this.index++;
|
|
45
|
+
indices.set(value, index);
|
|
46
|
+
stack.push([value, index]);
|
|
47
|
+
return index;
|
|
48
|
+
};
|
|
49
|
+
let i = 0;
|
|
50
|
+
while (stack.length > 0) {
|
|
51
|
+
const now = getNow();
|
|
52
|
+
if (++i % 6e3 === 0 && now - lastYieldTime >= TIME_LIMIT_MS) {
|
|
53
|
+
await yieldToMain();
|
|
54
|
+
lastYieldTime = getNow();
|
|
55
|
+
}
|
|
56
|
+
const [input, index] = stack.pop();
|
|
57
|
+
const partsForObj = (obj) => Object.keys(obj).map((k) => `"_${flattenValue(k)}":${flattenValue(obj[k])}`).join(",");
|
|
58
|
+
let error = null;
|
|
59
|
+
switch (typeof input) {
|
|
60
|
+
case "boolean":
|
|
61
|
+
case "number":
|
|
62
|
+
case "string":
|
|
63
|
+
str[index] = JSON.stringify(input);
|
|
64
|
+
break;
|
|
65
|
+
case "bigint":
|
|
66
|
+
str[index] = `["B","${input}"]`;
|
|
67
|
+
break;
|
|
68
|
+
case "symbol": {
|
|
69
|
+
const keyFor = Symbol.keyFor(input);
|
|
70
|
+
if (!keyFor) error = /* @__PURE__ */ new Error("Cannot encode symbol unless created with Symbol.for()");
|
|
71
|
+
else str[index] = `["Y",${JSON.stringify(keyFor)}]`;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "object": {
|
|
75
|
+
if (!input) {
|
|
76
|
+
str[index] = `-5`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
const isArray = Array.isArray(input);
|
|
80
|
+
let pluginHandled = false;
|
|
81
|
+
if (!isArray && plugins) for (const plugin of plugins) {
|
|
82
|
+
const pluginResult = plugin(input);
|
|
83
|
+
if (Array.isArray(pluginResult)) {
|
|
84
|
+
pluginHandled = true;
|
|
85
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
|
86
|
+
str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
|
87
|
+
if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
|
88
|
+
str[index] += "]";
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!pluginHandled) {
|
|
93
|
+
let result = isArray ? "[" : "{";
|
|
94
|
+
if (isArray) {
|
|
95
|
+
for (let i = 0; i < input.length; i++) result += (i ? "," : "") + (i in input ? flattenValue(input[i]) : -1);
|
|
96
|
+
str[index] = `${result}]`;
|
|
97
|
+
} else if (input instanceof Date) {
|
|
98
|
+
const dateTime = input.getTime();
|
|
99
|
+
str[index] = `["D",${Number.isNaN(dateTime) ? JSON.stringify("invalid") : dateTime}]`;
|
|
100
|
+
} else if (input instanceof URL) str[index] = `["U",${JSON.stringify(input.href)}]`;
|
|
101
|
+
else if (input instanceof RegExp) str[index] = `["R",${JSON.stringify(input.source)},${JSON.stringify(input.flags)}]`;
|
|
102
|
+
else if (input instanceof Set) if (input.size > 0) str[index] = `["S",${[...input].map((val) => flattenValue(val)).join(",")}]`;
|
|
103
|
+
else str[index] = `["S"]`;
|
|
104
|
+
else if (input instanceof Map) if (input.size > 0) str[index] = `["M",${[...input].flatMap(([k, v]) => [flattenValue(k), flattenValue(v)]).join(",")}]`;
|
|
105
|
+
else str[index] = `["M"]`;
|
|
106
|
+
else if (input instanceof Promise) {
|
|
107
|
+
str[index] = `["P",${index}]`;
|
|
108
|
+
deferred[index] = input;
|
|
109
|
+
} else if (input instanceof Error) {
|
|
110
|
+
str[index] = `["E",${JSON.stringify(input.message)}`;
|
|
111
|
+
if (input.name !== "Error") str[index] += `,${JSON.stringify(input.name)}`;
|
|
112
|
+
str[index] += "]";
|
|
113
|
+
} else if (Object.getPrototypeOf(input) === null) str[index] = `["N",{${partsForObj(input)}}]`;
|
|
114
|
+
else if (isPlainObject(input)) str[index] = `{${partsForObj(input)}}`;
|
|
115
|
+
else error = /* @__PURE__ */ new Error("Cannot encode object with prototype");
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
default: {
|
|
120
|
+
const isArray = Array.isArray(input);
|
|
121
|
+
let pluginHandled = false;
|
|
122
|
+
if (!isArray && plugins) for (const plugin of plugins) {
|
|
123
|
+
const pluginResult = plugin(input);
|
|
124
|
+
if (Array.isArray(pluginResult)) {
|
|
125
|
+
pluginHandled = true;
|
|
126
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
|
127
|
+
str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
|
128
|
+
if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
|
129
|
+
str[index] += "]";
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!pluginHandled) error = /* @__PURE__ */ new Error("Cannot encode function or unexpected type");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (error) {
|
|
137
|
+
let pluginHandled = false;
|
|
138
|
+
if (postPlugins) for (const plugin of postPlugins) {
|
|
139
|
+
const pluginResult = plugin(input);
|
|
140
|
+
if (Array.isArray(pluginResult)) {
|
|
141
|
+
pluginHandled = true;
|
|
142
|
+
const [pluginIdentifier, ...rest] = pluginResult;
|
|
143
|
+
str[index] = `[${JSON.stringify(pluginIdentifier)}`;
|
|
144
|
+
if (rest.length > 0) str[index] += `,${rest.map((v) => flattenValue(v)).join(",")}`;
|
|
145
|
+
str[index] += "]";
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!pluginHandled) throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
154
|
+
function isPlainObject(thing) {
|
|
155
|
+
const proto = Object.getPrototypeOf(thing);
|
|
156
|
+
return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
export { flatten };
|
|
@@ -0,0 +1,178 @@
|
|
|
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 { Deferred, createLineSplittingTransform } from "./utils.js";
|
|
12
|
+
import { flatten } from "./flatten.js";
|
|
13
|
+
import { unflatten } from "./unflatten.js";
|
|
14
|
+
//#region vendor/turbo-stream-v2/turbo-stream.ts
|
|
15
|
+
async function decode(readable, options) {
|
|
16
|
+
const { plugins } = options ?? {};
|
|
17
|
+
const done = new Deferred();
|
|
18
|
+
const reader = readable.pipeThrough(createLineSplittingTransform()).getReader();
|
|
19
|
+
const decoder = {
|
|
20
|
+
values: [],
|
|
21
|
+
hydrated: [],
|
|
22
|
+
deferred: {},
|
|
23
|
+
plugins
|
|
24
|
+
};
|
|
25
|
+
const decoded = await decodeInitial.call(decoder, reader);
|
|
26
|
+
let donePromise = done.promise;
|
|
27
|
+
if (decoded.done) done.resolve();
|
|
28
|
+
else donePromise = decodeDeferred.call(decoder, reader).then(done.resolve).catch((reason) => {
|
|
29
|
+
for (const deferred of Object.values(decoder.deferred)) deferred.reject(reason);
|
|
30
|
+
done.reject(reason);
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
done: donePromise.then(() => reader.closed),
|
|
34
|
+
value: decoded.value
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async function decodeInitial(reader) {
|
|
38
|
+
const read = await reader.read();
|
|
39
|
+
if (!read.value) throw new SyntaxError();
|
|
40
|
+
let line;
|
|
41
|
+
try {
|
|
42
|
+
line = JSON.parse(read.value);
|
|
43
|
+
} catch (reason) {
|
|
44
|
+
throw new SyntaxError();
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
done: read.done,
|
|
48
|
+
value: unflatten.call(this, line)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function decodeDeferred(reader) {
|
|
52
|
+
let read = await reader.read();
|
|
53
|
+
while (!read.done) {
|
|
54
|
+
if (!read.value) continue;
|
|
55
|
+
const line = read.value;
|
|
56
|
+
switch (line[0]) {
|
|
57
|
+
case "P": {
|
|
58
|
+
const colonIndex = line.indexOf(":");
|
|
59
|
+
const deferredId = Number(line.slice(1, colonIndex));
|
|
60
|
+
const deferred = this.deferred[deferredId];
|
|
61
|
+
if (!deferred) throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
|
62
|
+
const lineData = line.slice(colonIndex + 1);
|
|
63
|
+
let jsonLine;
|
|
64
|
+
try {
|
|
65
|
+
jsonLine = JSON.parse(lineData);
|
|
66
|
+
} catch (reason) {
|
|
67
|
+
throw new SyntaxError();
|
|
68
|
+
}
|
|
69
|
+
const value = unflatten.call(this, jsonLine);
|
|
70
|
+
deferred.resolve(value);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "E": {
|
|
74
|
+
const colonIndex = line.indexOf(":");
|
|
75
|
+
const deferredId = Number(line.slice(1, colonIndex));
|
|
76
|
+
const deferred = this.deferred[deferredId];
|
|
77
|
+
if (!deferred) throw new Error(`Deferred ID ${deferredId} not found in stream`);
|
|
78
|
+
const lineData = line.slice(colonIndex + 1);
|
|
79
|
+
let jsonLine;
|
|
80
|
+
try {
|
|
81
|
+
jsonLine = JSON.parse(lineData);
|
|
82
|
+
} catch (reason) {
|
|
83
|
+
throw new SyntaxError();
|
|
84
|
+
}
|
|
85
|
+
const value = unflatten.call(this, jsonLine);
|
|
86
|
+
deferred.reject(value);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
default: throw new SyntaxError();
|
|
90
|
+
}
|
|
91
|
+
read = await reader.read();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function encode(input, options) {
|
|
95
|
+
const { onComplete, plugins, postPlugins, signal } = options ?? {};
|
|
96
|
+
const encoder = {
|
|
97
|
+
deferred: {},
|
|
98
|
+
index: 0,
|
|
99
|
+
indices: /* @__PURE__ */ new Map(),
|
|
100
|
+
stringified: [],
|
|
101
|
+
plugins,
|
|
102
|
+
postPlugins,
|
|
103
|
+
signal
|
|
104
|
+
};
|
|
105
|
+
const textEncoder = new TextEncoder();
|
|
106
|
+
let lastSentIndex = 0;
|
|
107
|
+
return new ReadableStream({ async start(controller) {
|
|
108
|
+
const id = await flatten.call(encoder, input);
|
|
109
|
+
if (Array.isArray(id)) throw new Error("This should never happen");
|
|
110
|
+
if (id < 0) controller.enqueue(textEncoder.encode(`${id}\n`));
|
|
111
|
+
else {
|
|
112
|
+
controller.enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]\n`));
|
|
113
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
114
|
+
}
|
|
115
|
+
const seenPromises = /* @__PURE__ */ new WeakSet();
|
|
116
|
+
let processingChain = Promise.resolve();
|
|
117
|
+
if (Object.keys(encoder.deferred).length) {
|
|
118
|
+
let raceDone;
|
|
119
|
+
const racePromise = new Promise((resolve, reject) => {
|
|
120
|
+
raceDone = resolve;
|
|
121
|
+
if (signal) {
|
|
122
|
+
const rejectPromise = () => reject(signal.reason || /* @__PURE__ */ new Error("Signal was aborted."));
|
|
123
|
+
if (signal.aborted) rejectPromise();
|
|
124
|
+
else signal.addEventListener("abort", (event) => {
|
|
125
|
+
rejectPromise();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
while (Object.keys(encoder.deferred).length > 0) {
|
|
130
|
+
for (const [deferredId, deferred] of Object.entries(encoder.deferred)) {
|
|
131
|
+
if (seenPromises.has(deferred)) continue;
|
|
132
|
+
seenPromises.add(encoder.deferred[Number(deferredId)] = Promise.race([racePromise, deferred]).then((resolved) => {
|
|
133
|
+
processingChain = processingChain.then(async () => {
|
|
134
|
+
const id = await flatten.call(encoder, resolved);
|
|
135
|
+
if (Array.isArray(id)) {
|
|
136
|
+
controller.enqueue(textEncoder.encode(`P${deferredId}:[["Z",${id[0]}]]\n`));
|
|
137
|
+
encoder.index++;
|
|
138
|
+
lastSentIndex++;
|
|
139
|
+
} else if (id < 0) controller.enqueue(textEncoder.encode(`P${deferredId}:${id}\n`));
|
|
140
|
+
else {
|
|
141
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
142
|
+
controller.enqueue(textEncoder.encode(`P${deferredId}:[${values}]\n`));
|
|
143
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return processingChain;
|
|
147
|
+
}, (reason) => {
|
|
148
|
+
processingChain = processingChain.then(async () => {
|
|
149
|
+
if (!reason || typeof reason !== "object" || !(reason instanceof Error)) reason = /* @__PURE__ */ new Error("An unknown error occurred");
|
|
150
|
+
const id = await flatten.call(encoder, reason);
|
|
151
|
+
if (Array.isArray(id)) {
|
|
152
|
+
controller.enqueue(textEncoder.encode(`E${deferredId}:[["Z",${id[0]}]]\n`));
|
|
153
|
+
encoder.index++;
|
|
154
|
+
lastSentIndex++;
|
|
155
|
+
} else if (id < 0) controller.enqueue(textEncoder.encode(`E${deferredId}:${id}\n`));
|
|
156
|
+
else {
|
|
157
|
+
const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
|
|
158
|
+
controller.enqueue(textEncoder.encode(`E${deferredId}:[${values}]\n`));
|
|
159
|
+
lastSentIndex = encoder.stringified.length - 1;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return processingChain;
|
|
163
|
+
}).finally(() => {
|
|
164
|
+
delete encoder.deferred[Number(deferredId)];
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
await Promise.race(Object.values(encoder.deferred));
|
|
168
|
+
}
|
|
169
|
+
raceDone();
|
|
170
|
+
}
|
|
171
|
+
await Promise.all(Object.values(encoder.deferred));
|
|
172
|
+
await processingChain;
|
|
173
|
+
controller.close();
|
|
174
|
+
onComplete?.();
|
|
175
|
+
} });
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { decode, encode };
|