@teyik0/furin 0.7.0-alpha.3 → 0.8.0-alpha.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/README.md +1 -1
- package/dist/adapter/build.d.ts +9 -0
- package/dist/adapter/bun/server.d.ts +1 -0
- package/dist/adapter/bun.d.ts +7 -3
- package/dist/adapter/package.d.ts +1 -0
- package/dist/adapter/prerender.d.ts +21 -0
- package/dist/adapter/runtime-build.d.ts +24 -10
- package/dist/adapter/server-bundle.d.ts +20 -0
- package/dist/adapter/static.d.ts +2 -2
- package/dist/adapter/types.d.ts +81 -0
- package/dist/adapter/vercel/bootstrap.d.ts +5 -0
- package/dist/adapter/vercel/data.d.ts +23 -0
- package/dist/adapter/vercel/handler.d.ts +10 -0
- package/dist/adapter/vercel.d.ts +13 -3
- package/dist/adapter/vercel.js +516 -0
- package/dist/build/bun-build.d.ts +4 -0
- package/dist/build/compile-entry.ts +1 -0
- package/dist/build/discover-mounts-process.d.ts +1 -0
- package/dist/build/discover-mounts.d.ts +6 -0
- package/dist/build/elysia-aot-worker.d.ts +4 -0
- package/dist/build/elysia-aot.d.ts +7 -1
- package/dist/build/entry-template.d.ts +14 -7
- package/dist/build/entry-template.ts +33 -18
- package/dist/build/hydrate.d.ts +15 -2
- package/dist/build/index.d.ts +7 -3
- package/dist/build/index.js +8842 -15395
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/route-types.d.ts +8 -2
- package/dist/build/server-app-entry.d.ts +2 -2
- package/dist/build/shared.d.ts +3 -5
- package/dist/build/types.d.ts +16 -16
- package/dist/cache.js +117 -32
- package/dist/cli/config.d.ts +2 -2
- package/dist/cli/index.js +8953 -15269
- package/dist/client/chunks/client-brdfd773.js +852 -0
- package/dist/client/chunks/client-k29262a4.js +59 -0
- package/dist/client/chunks/client-k88668k7.js +159 -0
- package/dist/client/chunks/client-xy6g38kx.js +317 -0
- package/dist/client/default-screens.d.ts +0 -11
- package/dist/client/define-route.d.ts +2 -1
- package/dist/client/hmr.d.ts +1 -1
- package/dist/client/internal/runtime-types.d.ts +7 -1
- package/dist/client/link.d.ts +1 -0
- package/dist/client/link.js +1790 -4190
- package/dist/client/mutation.d.ts +5 -0
- package/dist/client/query-store.d.ts +17 -7
- package/dist/client/query.d.ts +6 -8
- package/dist/client/request-id.d.ts +1 -0
- package/dist/client/route-api.d.ts +4 -4
- package/dist/client/route-element.d.ts +51 -0
- package/dist/client/router/boundary-tree.d.ts +1 -9
- package/dist/client/router/cache-generation.d.ts +15 -0
- package/dist/client/router/context.d.ts +13 -2
- package/dist/client/router/fetch-observers.d.ts +9 -0
- package/dist/client/router/hmr-refresh.d.ts +12 -0
- package/dist/client/router/index.d.ts +5 -7
- package/dist/client/router/link-utils.d.ts +0 -2
- package/dist/client/router/navigation-controller.d.ts +76 -0
- package/dist/client/router/navigation.d.ts +1 -0
- package/dist/client/router/page-fetch.d.ts +38 -0
- package/dist/client/router/provider.d.ts +2 -3
- package/dist/client/router/search/index.d.ts +11 -4
- package/dist/client/router/search/index.js +60 -0
- package/dist/client/router/spa-response.d.ts +9 -26
- package/dist/client/router/sync-catch-up.d.ts +3 -2
- package/dist/client/router/transport.d.ts +4 -0
- package/dist/client/router/types.d.ts +120 -46
- package/dist/client/router/use-fetch-interception.d.ts +12 -0
- package/dist/client/router/use-history-sync.d.ts +7 -0
- package/dist/client/router/use-hmr-refresh.d.ts +8 -0
- package/dist/client/router/use-sync-stream.d.ts +16 -0
- package/dist/client/server-error.d.ts +4 -7
- package/dist/client/sync.d.ts +43 -30
- package/dist/client.d.ts +2 -1
- package/dist/client.js +279 -829
- package/dist/config.d.ts +11 -12
- package/dist/config.js +0 -30
- package/dist/define-route.d.ts +262 -517
- package/dist/devtools/protocol.d.ts +4 -3
- package/dist/furin.d.ts +41 -31
- package/dist/furin.js +20560 -18970
- package/dist/plugin/binding-scope.d.ts +15 -2
- package/dist/plugin/client-plugin.d.ts +19 -0
- package/dist/plugin/dead-code-elimination.d.ts +14 -3
- package/dist/plugin/dev-routes.d.ts +22 -0
- package/dist/plugin/hmr-data-signature.d.ts +3 -0
- package/dist/plugin/hmr-hook-signature.d.ts +9 -0
- package/dist/plugin/index.d.ts +1 -6
- package/dist/plugin/index.js +1753 -1214
- package/dist/plugin/module-bindings.d.ts +11 -0
- package/dist/plugin/module-transform.d.ts +29 -0
- package/dist/plugin/preflight.d.ts +8 -0
- package/dist/plugin/route-chains.d.ts +35 -0
- package/dist/plugin/route-config.d.ts +28 -0
- package/dist/plugin/route-modules.d.ts +35 -0
- package/dist/plugin/route-registry.d.ts +12 -0
- package/dist/plugin/route-tree.d.ts +43 -0
- package/dist/plugin/strip-server-stages.d.ts +10 -0
- package/dist/plugin/strip-server.d.ts +10 -0
- package/dist/plugin/transform-client-module.d.ts +3 -0
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +3 -2
- package/dist/routes.d.ts +15 -5
- package/dist/rsc/build/client-references.d.ts +8 -0
- package/dist/rsc/build/discover.d.ts +7 -0
- package/dist/rsc/build/flight-loader.d.ts +1 -0
- package/dist/rsc/build/index.d.ts +4 -1
- package/dist/rsc/build/paths.d.ts +2 -0
- package/dist/rsc/bundled-client-codec.d.ts +1 -0
- package/dist/rsc/client-codec.d.ts +3 -0
- package/dist/rsc/client-references.d.ts +22 -0
- package/dist/rsc/server-client-codec.d.ts +1 -0
- package/dist/rsc/server-codec.js +3889 -2
- package/dist/rsc/slot-proxy.d.ts +11 -0
- package/dist/rsc/transport-benchmark.d.ts +2 -1
- package/dist/rsc-client.js +16 -164
- package/dist/rsc-server.d.ts +1 -5
- package/dist/rsc.d.ts +1 -5
- package/dist/rsc.js +233 -73
- package/dist/server/assets/client-dir.d.ts +1 -0
- package/dist/server/auto-invalidate/index.d.ts +2 -2
- package/dist/server/auto-invalidate/plugin.d.ts +21 -15
- package/dist/server/auto-invalidate/types.d.ts +0 -2
- package/dist/server/bounded-body.d.ts +6 -0
- package/dist/server/browser-events/plugin.d.ts +4 -1
- package/dist/server/browser-events/shutdown.d.ts +1 -1
- package/dist/server/cache/dev-loader.d.ts +6 -1
- package/dist/server/cache/index.d.ts +4 -9
- package/dist/server/cache/invalidation.d.ts +7 -2
- package/dist/server/cache/isr-ssg.d.ts +6 -1
- package/dist/server/cache/page-cache.d.ts +5 -0
- package/dist/server/cache/purger.d.ts +14 -4
- package/dist/server/cache/redis/index.d.ts +1 -34
- package/dist/server/cache/redis/index.js +51 -25
- package/dist/server/cache/redis/scripts.d.ts +1 -1
- package/dist/server/cache/route-cache.d.ts +18 -2
- package/dist/server/cache/runtime-cache.d.ts +7 -0
- package/dist/server/context-logger.d.ts +6 -1
- package/dist/server/dev/graph.d.ts +4 -3
- package/dist/server/dev/runtime.d.ts +4 -0
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev/stack-location.d.ts +9 -0
- package/dist/server/dev-page-imports.d.ts +42 -0
- package/dist/server/dev-page-plugin.d.ts +2 -49
- package/dist/server/devtools/instrumentation.d.ts +1 -3
- package/dist/server/devtools/instrumentation.production.d.ts +0 -2
- package/dist/server/devtools/request-context.d.ts +7 -0
- package/dist/server/evlog.d.ts +18 -6
- package/dist/server/instance.d.ts +52 -44
- package/dist/server/internal.d.ts +51 -14
- package/dist/server/internal.js +9749 -2095
- package/dist/server/lang-detect.d.ts +4 -4
- package/dist/server/logger.d.ts +6 -0
- package/dist/server/logging/ingest-plugin.d.ts +32 -0
- package/dist/server/mode.d.ts +17 -0
- package/dist/server/prerender.d.ts +32 -0
- package/dist/server/prod/runtime.d.ts +5 -0
- package/dist/server/production-server.js +992 -726
- package/dist/server/registrations.d.ts +14 -0
- package/dist/server/render/assemble.d.ts +0 -22
- package/dist/server/render/buffered-render.d.ts +20 -0
- package/dist/server/render/document-stream.d.ts +45 -0
- package/dist/server/render/document.d.ts +1 -1
- package/dist/server/render/element.d.ts +2 -5
- package/dist/server/render/index.d.ts +4 -5
- package/dist/server/render/index.ts +4 -21
- package/dist/server/render/isr-revalidation.d.ts +5 -0
- package/dist/server/render/isr-shared-cache.d.ts +23 -0
- package/dist/server/render/isr.d.ts +19 -1
- package/dist/server/render/loader-errors.d.ts +33 -0
- package/dist/server/render/loader-segments.d.ts +40 -0
- package/dist/server/render/loaders.d.ts +16 -32
- package/dist/server/render/mixed-cache.d.ts +2 -2
- package/dist/server/render/navigation-head.d.ts +13 -0
- package/dist/server/render/not-found-plugin.d.ts +18 -0
- package/dist/server/render/observe-loader.d.ts +1 -0
- package/dist/server/render/ppr-document.d.ts +1 -1
- package/dist/server/render/ppr-request.d.ts +0 -2
- package/dist/server/render/ppr-route.d.ts +13 -2
- package/dist/server/render/prepare-render.d.ts +57 -0
- package/dist/server/render/request-loaders.d.ts +19 -0
- package/dist/server/render/route-frame-transport.d.ts +7 -1
- package/dist/server/render/shell.d.ts +1 -1
- package/dist/server/render/shell.ts +1 -1
- package/dist/server/render/ssr-transport.d.ts +11 -0
- package/dist/server/render/ssr.d.ts +1 -116
- package/dist/server/render/static-params.d.ts +15 -0
- package/dist/server/router/discovery.d.ts +1 -0
- package/dist/server/router/dispatch.d.ts +96 -0
- package/dist/server/router/hmr.d.ts +14 -24
- package/dist/server/router/patterns.d.ts +15 -20
- package/dist/server/router/plugin.d.ts +26 -24
- package/dist/server/router/schemas.d.ts +6 -24
- package/dist/server/router/types.d.ts +0 -2
- package/dist/server/runtime-env.d.ts +6 -1
- package/dist/server/static-export.d.ts +38 -0
- package/dist/server/static-export.js +10667 -0
- package/dist/server/sync/adapter.d.ts +11 -0
- package/dist/server/sync/atomic.d.ts +0 -2
- package/dist/server/sync/config.d.ts +0 -1
- package/dist/server/sync/drizzle/index.js +112 -68
- package/dist/server/sync/fingerprint.d.ts +0 -1
- package/dist/server/sync/index.d.ts +2 -6
- package/dist/server/sync/index.js +1689 -1364
- package/dist/server/sync/invalidate-sync.d.ts +10 -0
- package/dist/server/sync/plugin.d.ts +18 -55
- package/dist/server/sync/postgres/execute.d.ts +2 -2
- package/dist/server/sync/postgres/index.d.ts +3 -1
- package/dist/server/sync/postgres/index.js +68 -37
- package/dist/server/sync/postgres/migration.sql +2 -0
- package/dist/server/sync/principal-journal.d.ts +11 -0
- package/dist/server/sync/prisma/index.js +74 -39
- package/dist/server/sync/queries.d.ts +57 -16
- package/dist/server/sync/redis/index.d.ts +2 -1
- package/dist/server/sync/redis/index.js +49 -5
- package/dist/server/sync/redis/scripts.d.ts +2 -1
- package/dist/server/sync/response.d.ts +3 -0
- package/dist/server/sync/runtime.d.ts +5 -1
- package/dist/server/sync/sqlite/index.d.ts +3 -1
- package/dist/server/sync/sqlite/index.js +58 -27
- package/dist/server/sync/stream.d.ts +32 -7
- package/dist/server/weak-registry.d.ts +9 -0
- package/dist/shared/await.d.ts +2 -1
- package/dist/shared/compact-json.d.ts +1 -0
- package/dist/shared/defer.d.ts +1 -1
- package/dist/shared/deferred-ndjson.d.ts +3 -2
- package/dist/shared/elysia-contract.d.ts +2 -0
- package/dist/shared/in-memory-apps.d.ts +7 -0
- package/dist/shared/invalidation-header.d.ts +13 -0
- package/dist/shared/navigation-data.d.ts +7 -0
- package/dist/shared/prefix.d.ts +11 -5
- package/dist/shared/route-frame.d.ts +3 -0
- package/dist/shared/route-map.d.ts +7 -0
- package/dist/shared/route-matches.d.ts +41 -0
- package/dist/shared/route-specificity.d.ts +2 -0
- package/dist/shared/search-params.d.ts +2 -3
- package/dist/shared/sync-query.d.ts +6 -13
- package/dist/shared/utils/ast-walk.d.ts +3 -11
- package/package.json +32 -21
- package/src/adapter/README.md +37 -16
- package/src/adapter/build.ts +269 -0
- package/src/adapter/bun/server.ts +14 -0
- package/src/adapter/bun.ts +89 -265
- package/src/adapter/furin-app.d.ts +14 -0
- package/src/adapter/package.ts +31 -27
- package/src/adapter/prerender.ts +97 -0
- package/src/adapter/runtime-build.ts +83 -93
- package/src/adapter/server-bundle.ts +110 -0
- package/src/adapter/static.ts +259 -247
- package/src/adapter/types.ts +89 -0
- package/src/adapter/vercel/bootstrap.ts +85 -0
- package/src/adapter/vercel/data.ts +21 -0
- package/src/adapter/vercel/handler.ts +132 -0
- package/src/adapter/vercel.ts +329 -659
- package/src/build/bun-build.ts +3 -0
- package/src/build/client.ts +22 -60
- package/src/build/compile-entry.ts +1 -0
- package/src/build/discover-mounts-process.ts +13 -0
- package/src/build/discover-mounts.ts +40 -0
- package/src/build/elysia-aot-worker.ts +84 -2
- package/src/build/elysia-aot.ts +61 -2
- package/src/build/entry-template.ts +33 -18
- package/src/build/hydrate.ts +122 -44
- package/src/build/index.ts +156 -108
- package/src/build/private-server-sourcemaps.ts +5 -0
- package/src/build/production-instrumentation.ts +22 -19
- package/src/build/route-types.ts +93 -11
- package/src/build/server-app-entry.ts +4 -21
- package/src/build/shared.ts +9 -41
- package/src/build/types.ts +14 -20
- package/src/build/virtual-entry.ts +2 -4
- package/src/cli/config.ts +133 -6
- package/src/cli/index.ts +59 -21
- package/src/cli/preview.ts +2 -1
- package/src/client/boundaries.tsx +5 -14
- package/src/client/default-screens.tsx +2 -2
- package/src/client/define-route.ts +3 -2
- package/src/client/hmr.ts +1 -1
- package/src/client/internal/runtime-types.ts +7 -1
- package/src/client/link.tsx +80 -43
- package/src/client/mutation.ts +98 -3
- package/src/client/query-store.ts +160 -29
- package/src/client/query.tsx +12 -29
- package/src/client/request-id.ts +10 -0
- package/src/client/route-api.tsx +6 -6
- package/src/client/route-element.tsx +155 -0
- package/src/client/router/boundary-tree.tsx +2 -93
- package/src/client/router/cache-generation.ts +37 -0
- package/src/client/router/context.ts +40 -4
- package/src/client/router/fetch-observers.ts +46 -0
- package/src/client/router/hmr-refresh.ts +50 -0
- package/src/client/router/index.ts +7 -29
- package/src/client/router/link-utils.ts +19 -31
- package/src/client/router/navigation-controller.ts +547 -0
- package/src/client/router/navigation.ts +3 -2
- package/src/client/router/optimistic.ts +2 -3
- package/src/client/router/page-fetch.ts +272 -0
- package/src/client/router/provider.tsx +223 -1079
- package/src/client/router/search/index.ts +38 -14
- package/src/client/router/spa-response.ts +19 -70
- package/src/client/router/sync-catch-up.ts +65 -7
- package/src/client/router/transport.ts +23 -0
- package/src/client/router/types.ts +203 -61
- package/src/client/router/use-fetch-interception.ts +52 -0
- package/src/client/router/use-history-sync.ts +56 -0
- package/src/client/router/use-hmr-refresh.ts +51 -0
- package/src/client/router/use-sync-stream.ts +129 -0
- package/src/client/server-error.ts +2 -40
- package/src/client/sync.ts +268 -378
- package/src/client.ts +2 -7
- package/src/config.ts +23 -45
- package/src/define-route.ts +487 -882
- package/src/devtools/devtools-element.js +10 -3
- package/src/devtools/protocol.ts +3 -3
- package/src/furin.ts +253 -1086
- package/src/plugin/binding-scope.ts +219 -94
- package/src/plugin/client-plugin.ts +145 -0
- package/src/plugin/dead-code-elimination.ts +390 -111
- package/src/plugin/dev-routes.ts +453 -0
- package/src/plugin/hmr-data-signature.ts +161 -0
- package/src/plugin/hmr-dependencies.ts +2 -4
- package/src/plugin/hmr-hook-signature.ts +252 -0
- package/src/plugin/index.ts +3 -96
- package/src/plugin/module-bindings.ts +216 -0
- package/src/plugin/module-transform.ts +63 -0
- package/src/plugin/preflight.ts +66 -0
- package/src/plugin/route-chains.ts +309 -0
- package/src/plugin/route-config.ts +451 -0
- package/src/plugin/route-modules.ts +209 -0
- package/src/plugin/route-registry.ts +316 -0
- package/src/plugin/route-tree.ts +248 -0
- package/src/plugin/strip-server-stages.ts +197 -0
- package/src/plugin/strip-server.ts +22 -0
- package/src/plugin/transform-client-module.ts +36 -31
- package/src/plugin/transform-client.ts +33 -1114
- package/src/plugin/transform-dev-page.ts +84 -92
- package/src/plugin/transform-isomorphic.ts +396 -185
- package/src/routes.ts +15 -5
- package/src/rsc/build/client-references.ts +267 -0
- package/src/rsc/build/discover.ts +226 -0
- package/src/rsc/build/flight-loader.ts +69 -0
- package/src/rsc/build/index.ts +53 -31
- package/src/rsc/build/paths.ts +7 -0
- package/src/rsc/bundled-client-codec.ts +4 -0
- package/src/rsc/client-codec.ts +12 -3
- package/src/rsc/client-references.ts +138 -0
- package/src/rsc/codec.ts +30 -21
- package/src/rsc/flight-drain.ts +6 -29
- package/src/rsc/react-server-dom-webpack.d.ts +1 -1
- package/src/rsc/server-client-codec.ts +14 -0
- package/src/rsc/server-codec.ts +5 -8
- package/src/rsc/slot-proxy.ts +34 -0
- package/src/rsc/transport-benchmark.ts +1 -1
- package/src/rsc-server.tsx +5 -23
- package/src/rsc.tsx +5 -29
- package/src/server/assets/client-dir.ts +110 -0
- package/src/server/assets/production.ts +1 -1
- package/src/server/auto-invalidate/index.ts +2 -7
- package/src/server/auto-invalidate/plugin.ts +43 -15
- package/src/server/auto-invalidate/registry.ts +6 -6
- package/src/server/auto-invalidate/runtime.ts +16 -98
- package/src/server/auto-invalidate/types.ts +0 -6
- package/src/server/bounded-body.ts +38 -0
- package/src/server/browser-events/plugin.ts +109 -22
- package/src/server/browser-events/shutdown.ts +28 -9
- package/src/server/cache/dev-loader.ts +30 -16
- package/src/server/cache/index.ts +2 -15
- package/src/server/cache/invalidation.ts +27 -46
- package/src/server/cache/isr-ssg.ts +6 -1
- package/src/server/cache/isr.ts +11 -11
- package/src/server/cache/page-cache-state.ts +2 -2
- package/src/server/cache/page-cache.ts +13 -9
- package/src/server/cache/purger.ts +64 -8
- package/src/server/cache/redis/index.ts +17 -27
- package/src/server/cache/redis/scripts.ts +21 -4
- package/src/server/cache/registry.ts +3 -3
- package/src/server/cache/route-cache.ts +47 -13
- package/src/server/cache/runtime-cache.ts +144 -24
- package/src/server/cache/ssg.ts +7 -5
- package/src/server/context-logger.ts +46 -8
- package/src/server/dev/diagnostics.ts +6 -56
- package/src/server/dev/error.ts +3 -34
- package/src/server/dev/graph.ts +35 -22
- package/src/server/dev/rewrite-module-specifiers.ts +15 -19
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev/runtime.ts +404 -0
- package/src/server/dev/stack-location.ts +46 -0
- package/src/server/dev-page-imports.ts +183 -0
- package/src/server/dev-page-plugin.ts +39 -302
- package/src/server/devtools/hub.ts +3 -3
- package/src/server/devtools/instrumentation.production.ts +0 -8
- package/src/server/devtools/instrumentation.ts +6 -8
- package/src/server/devtools/plugin.ts +2 -1
- package/src/server/devtools/request-context.ts +67 -16
- package/src/server/evlog.ts +119 -55
- package/src/server/instance.ts +187 -138
- package/src/server/internal.ts +66 -62
- package/src/server/lang-detect.ts +31 -22
- package/src/server/logger.ts +20 -7
- package/src/server/logging/ingest-plugin.ts +123 -0
- package/src/server/mode.ts +19 -0
- package/src/server/prerender.ts +122 -0
- package/src/server/prod/runtime.ts +181 -0
- package/src/server/production-server.ts +43 -17
- package/src/server/registrations.ts +38 -0
- package/src/server/render/assemble.ts +5 -8
- package/src/server/render/buffered-render.ts +171 -0
- package/src/server/render/document-stream.ts +188 -0
- package/src/server/render/document.tsx +5 -3
- package/src/server/render/element.tsx +6 -73
- package/src/server/render/index.ts +4 -21
- package/src/server/render/isr-revalidation.ts +246 -0
- package/src/server/render/isr-shared-cache.ts +141 -0
- package/src/server/render/isr.ts +212 -516
- package/src/server/render/loader-errors.ts +183 -0
- package/src/server/render/loader-segments.ts +149 -0
- package/src/server/render/loaders.ts +126 -547
- package/src/server/render/mixed-cache.ts +28 -27
- package/src/server/render/navigation-head.ts +33 -0
- package/src/server/render/not-found-plugin.ts +31 -0
- package/src/server/render/not-found.ts +32 -8
- package/src/server/render/observe-loader.ts +46 -0
- package/src/server/render/ppr-document.ts +36 -14
- package/src/server/render/ppr-request.ts +2 -2
- package/src/server/render/ppr-route.ts +79 -18
- package/src/server/render/prepare-render.ts +251 -0
- package/src/server/render/request-loaders.ts +216 -0
- package/src/server/render/route-frame-transport.ts +41 -4
- package/src/server/render/shell.ts +1 -1
- package/src/server/render/ssg.ts +9 -20
- package/src/server/render/ssr-transport.ts +221 -0
- package/src/server/render/ssr.ts +95 -956
- package/src/server/render/static-params.ts +32 -0
- package/src/server/render/template.ts +7 -7
- package/src/server/router/discovery.ts +82 -159
- package/src/server/router/dispatch.ts +337 -0
- package/src/server/router/hmr.ts +177 -190
- package/src/server/router/patterns.ts +39 -65
- package/src/server/router/plugin.ts +234 -359
- package/src/server/router/schemas.ts +6 -39
- package/src/server/router/source-version.ts +5 -4
- package/src/server/router/types.ts +0 -2
- package/src/server/runtime-env.ts +6 -1
- package/src/server/static-export.ts +143 -0
- package/src/server/sync/adapter.ts +11 -0
- package/src/server/sync/atomic.ts +16 -36
- package/src/server/sync/config.ts +6 -14
- package/src/server/sync/drizzle/index.ts +12 -20
- package/src/server/sync/fingerprint.ts +1 -1
- package/src/server/sync/index.ts +2 -10
- package/src/server/sync/invalidate-sync.ts +31 -0
- package/src/server/sync/mutation-handler.ts +6 -0
- package/src/server/sync/plugin.ts +171 -129
- package/src/server/sync/postgres/execute.ts +9 -1
- package/src/server/sync/postgres/index.ts +71 -39
- package/src/server/sync/postgres/migration.sql +2 -0
- package/src/server/sync/principal-journal.ts +78 -0
- package/src/server/sync/prisma/index.ts +1 -0
- package/src/server/sync/queries.ts +133 -40
- package/src/server/sync/query-context.ts +38 -5
- package/src/server/sync/redis/index.ts +34 -6
- package/src/server/sync/redis/scripts.ts +10 -1
- package/src/server/sync/response.ts +47 -67
- package/src/server/sync/runtime.ts +24 -7
- package/src/server/sync/sqlite/index.ts +92 -61
- package/src/server/sync/sqlite/migration.sql +1 -0
- package/src/server/sync/stream.ts +47 -26
- package/src/server/sync/validation.ts +1 -1
- package/src/server/weak-registry.ts +37 -0
- package/src/shared/await.tsx +2 -1
- package/src/shared/compact-json.ts +1 -1
- package/src/shared/defer.ts +1 -1
- package/src/shared/deferred-ndjson.ts +142 -120
- package/src/shared/elysia-contract.ts +7 -0
- package/src/shared/error.ts +1 -4
- package/src/shared/in-memory-apps.ts +24 -0
- package/src/shared/invalidation-header.ts +38 -0
- package/src/shared/navigation-data.ts +29 -0
- package/src/shared/prefix.ts +42 -6
- package/src/shared/route-frame.ts +82 -26
- package/src/shared/route-map.ts +23 -39
- package/src/shared/route-matches.ts +59 -0
- package/src/shared/route-specificity.ts +28 -0
- package/src/shared/search-params.ts +6 -35
- package/src/shared/sync-query.ts +30 -23
- package/src/shared/utils/ast-walk.ts +9 -25
- package/src/shared/utils/index.ts +1 -1
- package/dist/build/scan-server.d.ts +0 -14
- package/dist/build/ssg-cache.d.ts +0 -18
- package/dist/plugin/route-config-autofix.d.ts +0 -31
- package/dist/plugin/routes.d.ts +0 -34
- package/dist/server/router/hmr.production.d.ts +0 -7
- package/src/build/scan-server.ts +0 -112
- package/src/build/ssg-cache.ts +0 -126
- package/src/plugin/route-config-autofix.ts +0 -1149
- package/src/plugin/routes.ts +0 -1140
- package/src/server/router/hmr.production.ts +0 -18
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function createRequestId(): string {
|
|
2
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
3
|
+
return globalThis.crypto.randomUUID();
|
|
4
|
+
}
|
|
5
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
6
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
7
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
8
|
+
}
|
|
9
|
+
return `${Date.now()}-${Math.random()}`;
|
|
10
|
+
}
|
package/src/client/route-api.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteMap } from "@teyik0/furin/routes";
|
|
2
2
|
import { type Context, createContext, createElement, type ReactNode, useContext } from "react";
|
|
3
3
|
import type { RouteLoaderData, RouteParams } from "../define-route.ts";
|
|
4
4
|
|
|
@@ -65,11 +65,11 @@ function useRouteSnapshot(pattern: string): RouteSnapshot {
|
|
|
65
65
|
return snapshot;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function getRouteApi<Pattern extends keyof
|
|
68
|
+
export function getRouteApi<Pattern extends keyof RouteMap & string>(pattern: Pattern) {
|
|
69
69
|
return {
|
|
70
|
-
useLoaderData: (): RouteLoaderData<
|
|
71
|
-
useRouteSnapshot(pattern).data as RouteLoaderData<
|
|
72
|
-
useParams: (): ResolvedRouteParams<
|
|
73
|
-
useRouteSnapshot(pattern).params as ResolvedRouteParams<
|
|
70
|
+
useLoaderData: (): RouteLoaderData<RouteMap[Pattern]> =>
|
|
71
|
+
useRouteSnapshot(pattern).data as RouteLoaderData<RouteMap[Pattern]>,
|
|
72
|
+
useParams: (): ResolvedRouteParams<RouteMap[Pattern]> =>
|
|
73
|
+
useRouteSnapshot(pattern).params as ResolvedRouteParams<RouteMap[Pattern]>,
|
|
74
74
|
};
|
|
75
75
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createElement, type ElementType, type ReactNode } from "react";
|
|
2
|
+
import type { ErrorComponent } from "../shared/error.ts";
|
|
3
|
+
import type { NotFoundComponent } from "../shared/not-found.ts";
|
|
4
|
+
import { pageKey } from "../shared/page-key.ts";
|
|
5
|
+
import { type RouteMatchFailure, serializedRouteMatches } from "../shared/route-matches.ts";
|
|
6
|
+
import { type BoundaryOptions, wrapSegmentBoundaries } from "./boundaries.tsx";
|
|
7
|
+
import { DefaultErrorFallback, DefaultNotFoundFallback } from "./default-screens.tsx";
|
|
8
|
+
import { FurinDocumentFallback } from "./document.tsx";
|
|
9
|
+
import type { RuntimeData, RuntimeRoute } from "./internal/runtime-types.ts";
|
|
10
|
+
import { withRouteSnapshot } from "./route-api.tsx";
|
|
11
|
+
|
|
12
|
+
/** A segment's own loader data, or why it has none. */
|
|
13
|
+
type RouteMatch = { loaderData: RuntimeData; status: "success" } | RouteMatchFailure;
|
|
14
|
+
|
|
15
|
+
export interface RouteBoundary {
|
|
16
|
+
depth: number;
|
|
17
|
+
error?: ErrorComponent;
|
|
18
|
+
notFound?: NotFoundComponent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type RootBoundary = Omit<RouteBoundary, "depth">;
|
|
22
|
+
|
|
23
|
+
export interface RouteElementInput {
|
|
24
|
+
/** Boundaries declared along the route, shallow → deep. */
|
|
25
|
+
boundaries: readonly RouteBoundary[];
|
|
26
|
+
/** Client reset wiring for the interleaved boundaries; `undefined` on the server. */
|
|
27
|
+
boundaryOptions: BoundaryOptions | undefined;
|
|
28
|
+
/** Route chain, index 0 = root. */
|
|
29
|
+
chain: readonly RuntimeRoute[];
|
|
30
|
+
/** Flat render data: the page's props plus `__furinMatches`. */
|
|
31
|
+
data: RuntimeData;
|
|
32
|
+
/** `undefined` when no page matched the URL. */
|
|
33
|
+
page: { component: ElementType; pattern: string } | undefined;
|
|
34
|
+
/** Passed to the rendered `error.tsx`. */
|
|
35
|
+
reset: () => void;
|
|
36
|
+
/** The root directory's own conventions, used when the root segment failed. */
|
|
37
|
+
rootBoundary: RootBoundary | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function decodeRouteMatches(data: RuntimeData): RouteMatch[] {
|
|
41
|
+
return serializedRouteMatches(data).map((match) =>
|
|
42
|
+
match.status === "success"
|
|
43
|
+
? {
|
|
44
|
+
loaderData: Object.fromEntries(
|
|
45
|
+
Object.entries(match.fields).map(([field, key]) => [field, data[key]])
|
|
46
|
+
),
|
|
47
|
+
status: "success",
|
|
48
|
+
}
|
|
49
|
+
: match
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Picks the boundary that renders a failure of segment `index`. A segment's
|
|
55
|
+
* own boundary sits inside its layout, so a layout failure bubbles to a
|
|
56
|
+
* shallower boundary, as `error.tsx` does in the Next.js App Router. When no
|
|
57
|
+
* deeper boundary applies, the root directory's boundary (else the built-in
|
|
58
|
+
* screen) renders inside the root layout. The root segment has no layout
|
|
59
|
+
* above it: its failure renders inside the minimal document (`depth: -1`).
|
|
60
|
+
*/
|
|
61
|
+
export function selectRouteBoundary<Kind extends "error" | "notFound">(
|
|
62
|
+
boundaries: readonly RouteBoundary[],
|
|
63
|
+
rootBoundary: RootBoundary | undefined,
|
|
64
|
+
index: number,
|
|
65
|
+
kind: Kind
|
|
66
|
+
): { component: RootBoundary[Kind]; depth: number } {
|
|
67
|
+
const boundary = boundaries.findLast(
|
|
68
|
+
(candidate) => candidate.depth < index && candidate[kind] !== undefined
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
component: boundary?.[kind] ?? rootBoundary?.[kind],
|
|
72
|
+
depth: index === 0 ? -1 : (boundary?.depth ?? 0),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function wrapLayout(route: RuntimeRoute | undefined, props: RuntimeData, element: ReactNode) {
|
|
77
|
+
return route?.layout ? createElement(route.layout as ElementType, props, element) : element;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function failureElement(
|
|
81
|
+
failure: RouteMatchFailure,
|
|
82
|
+
component: ErrorComponent | NotFoundComponent | undefined,
|
|
83
|
+
reset: () => void
|
|
84
|
+
): ReactNode {
|
|
85
|
+
if (failure.status === "error") {
|
|
86
|
+
return createElement((component as ErrorComponent | undefined) ?? DefaultErrorFallback, {
|
|
87
|
+
error: failure.error,
|
|
88
|
+
reset,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return createElement((component as NotFoundComponent | undefined) ?? DefaultNotFoundFallback, {
|
|
92
|
+
error: failure.error,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Builds the route's React tree from its matches. SSR, hydration and client
|
|
98
|
+
* navigation all call this, so they render the same tree for the same payload.
|
|
99
|
+
*
|
|
100
|
+
* Every layout receives its own loader data merged over its ancestors', plus
|
|
101
|
+
* `params`, `path` and `query`, whether the page succeeded or not. The page
|
|
102
|
+
* receives the flat payload.
|
|
103
|
+
*/
|
|
104
|
+
export function resolveRouteElement(input: RouteElementInput): ReactNode {
|
|
105
|
+
const { boundaries, chain, data, page } = input;
|
|
106
|
+
const matches = decodeRouteMatches(data);
|
|
107
|
+
const context = { params: data.params, path: data.path, query: data.query };
|
|
108
|
+
const props: RuntimeData[] = [];
|
|
109
|
+
let inherited: RuntimeData = {};
|
|
110
|
+
for (const match of matches) {
|
|
111
|
+
if (match.status !== "success") {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
inherited = { ...inherited, ...match.loaderData };
|
|
115
|
+
props.push({ ...inherited, ...context });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const index = matches.findIndex((match) => match.status !== "success");
|
|
119
|
+
const failure = matches[index];
|
|
120
|
+
if (failure && failure.status !== "success") {
|
|
121
|
+
const { component, depth } = selectRouteBoundary(
|
|
122
|
+
boundaries,
|
|
123
|
+
input.rootBoundary,
|
|
124
|
+
index,
|
|
125
|
+
failure.status
|
|
126
|
+
);
|
|
127
|
+
let element = failureElement(failure, component, input.reset);
|
|
128
|
+
for (let layout = depth; layout >= 0; layout -= 1) {
|
|
129
|
+
element = wrapLayout(chain[layout], props[layout] ?? context, element);
|
|
130
|
+
}
|
|
131
|
+
return depth < 0 ? createElement(FurinDocumentFallback, null, element) : element;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!page) {
|
|
135
|
+
throw new Error("[furin] internal invariant: a successful route render requires a page.");
|
|
136
|
+
}
|
|
137
|
+
const pageProps = Object.fromEntries(
|
|
138
|
+
Object.entries(data).filter(([key]) => !key.startsWith("__furin"))
|
|
139
|
+
);
|
|
140
|
+
let element: ReactNode = createElement(page.component, {
|
|
141
|
+
...pageProps,
|
|
142
|
+
key: pageKey(page.pattern, pageProps, chain.at(-1)?.remountDeps),
|
|
143
|
+
});
|
|
144
|
+
// Inside-out: a boundary sits inside the layout at its depth, so it catches
|
|
145
|
+
// that layout's children but not the layout itself.
|
|
146
|
+
for (let layout = chain.length - 1; layout >= 0; layout -= 1) {
|
|
147
|
+
for (const boundary of boundaries.toReversed()) {
|
|
148
|
+
if (boundary.depth === layout) {
|
|
149
|
+
element = wrapSegmentBoundaries(element, boundary, input.boundaryOptions);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
element = wrapLayout(chain[layout], props[layout] ?? pageProps, element);
|
|
153
|
+
}
|
|
154
|
+
return withRouteSnapshot(element, page.pattern, pageProps);
|
|
155
|
+
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import
|
|
3
|
-
import { createElement } from "react";
|
|
4
|
-
import { pageKey } from "../../shared/page-key.ts";
|
|
5
|
-
import { type BoundaryOptions, FurinErrorBoundary, wrapSegmentBoundaries } from "../boundaries.tsx";
|
|
6
|
-
import type { RuntimeRoute } from "../internal/runtime-types.ts";
|
|
7
|
-
import { withRouteSnapshot } from "../route-api.tsx";
|
|
8
|
-
import { FurinServerError } from "../server-error.ts";
|
|
2
|
+
import { FurinErrorBoundary } from "../boundaries.tsx";
|
|
9
3
|
import { RouterContext } from "./context.ts";
|
|
10
|
-
import type {
|
|
11
|
-
ClientSegmentBoundary,
|
|
12
|
-
LoadedClientRoute,
|
|
13
|
-
RootBoundaryOptions,
|
|
14
|
-
RouterContextValue,
|
|
15
|
-
} from "./types.ts";
|
|
4
|
+
import type { RootBoundaryOptions, RouterContextValue } from "./types.ts";
|
|
16
5
|
|
|
17
6
|
/**
|
|
18
7
|
* Composes the outermost tree produced by `RouterProvider`:
|
|
@@ -40,83 +29,3 @@ export function buildRouterTree(
|
|
|
40
29
|
</RouterContext.Provider>
|
|
41
30
|
);
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Internal helper component that throws a `FurinServerError` during render
|
|
46
|
-
* so the nearest `<FurinErrorBoundary>` catches it and renders the user's
|
|
47
|
-
* `error.tsx` (or the built-in default) — without forcing a full-page reload.
|
|
48
|
-
*/
|
|
49
|
-
function RouteErrorThrower({
|
|
50
|
-
error,
|
|
51
|
-
}: {
|
|
52
|
-
error: { digest: string; message: string; status: number };
|
|
53
|
-
}): React.ReactElement {
|
|
54
|
-
throw new FurinServerError(error);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** @internal Exported for unit testing only. */
|
|
58
|
-
export function buildPageElement(
|
|
59
|
-
match: LoadedClientRoute,
|
|
60
|
-
root: RuntimeRoute | null,
|
|
61
|
-
data: Record<string, unknown>,
|
|
62
|
-
options: BoundaryOptions | undefined,
|
|
63
|
-
error: { digest: string; message: string; status: number } | undefined
|
|
64
|
-
): React.ReactNode {
|
|
65
|
-
let element: React.ReactNode = error
|
|
66
|
-
? createElement(RouteErrorThrower, { error })
|
|
67
|
-
: createElement(match.component, {
|
|
68
|
-
...data,
|
|
69
|
-
key: pageKey(match.pattern, data, match.pageRoute.remountDeps),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Reconstruct the FULL route chain (shallow→deep, index 0 = root) by walking
|
|
73
|
-
// parents. Boundary depths refer to these indices, including routes without
|
|
74
|
-
// layouts, so server and client attach boundaries at the same positions.
|
|
75
|
-
const chain: RuntimeRoute[] = [];
|
|
76
|
-
let current: RuntimeRoute | undefined = match.pageRoute;
|
|
77
|
-
while (current) {
|
|
78
|
-
chain.unshift(current);
|
|
79
|
-
current = current.parent;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Index boundaries by depth for O(1) lookup. A boundary's `depth` maps 1:1 to
|
|
83
|
-
// the route-chain index (depth 0 = root layout, handled separately below).
|
|
84
|
-
const byDepth = new Map<number, ClientSegmentBoundary[]>();
|
|
85
|
-
for (const segment of match.segmentBoundaries ?? []) {
|
|
86
|
-
const boundaries = byDepth.get(segment.depth) ?? [];
|
|
87
|
-
boundaries.unshift(segment);
|
|
88
|
-
byDepth.set(segment.depth, boundaries);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// When a root route is present it occupies chain index 0 and is wrapped
|
|
92
|
-
// separately below (root layout + depth-0 boundary), mirroring the server's
|
|
93
|
-
// `buildElement`. When `root` is null there is no separate root, so chain
|
|
94
|
-
// index 0 is an ordinary route whose layout + boundary participate in the
|
|
95
|
-
// loop too.
|
|
96
|
-
const rootOffset = root ? 1 : 0;
|
|
97
|
-
|
|
98
|
-
// Inside-out: at each non-root depth wrap the subtree with its same-depth
|
|
99
|
-
// boundary (so the boundary sits INSIDE the layout), then wrap with the
|
|
100
|
-
// layout itself when this route declares one.
|
|
101
|
-
for (let i = chain.length - 1; i >= rootOffset; i -= 1) {
|
|
102
|
-
for (const segment of byDepth.get(i) ?? []) {
|
|
103
|
-
element = wrapSegmentBoundaries(element, segment, options);
|
|
104
|
-
}
|
|
105
|
-
const Layout = chain[i]?.layout;
|
|
106
|
-
if (Layout) {
|
|
107
|
-
element = createElement(Layout as ElementType, data, element);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (root) {
|
|
112
|
-
// Depth 0 boundary wraps EVERYTHING below the root layout.
|
|
113
|
-
for (const segment of byDepth.get(0) ?? []) {
|
|
114
|
-
element = wrapSegmentBoundaries(element, segment, options);
|
|
115
|
-
}
|
|
116
|
-
if (root.layout) {
|
|
117
|
-
element = createElement(root.layout as ElementType, data, element);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return error ? element : withRouteSnapshot(element, match.pattern, data);
|
|
122
|
-
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RouterState } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
type Affects = (href: string, snapshot: RouterState) => boolean;
|
|
4
|
+
|
|
5
|
+
/** Invalidations kept to prove freshness; older snapshots are treated as stale. */
|
|
6
|
+
const MAX_TRACKED_INVALIDATIONS = 64;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Monotonic generation bumped by every prefetch-cache invalidation. A snapshot
|
|
10
|
+
* stamped with the generation at which its fetch started is fresh only when no
|
|
11
|
+
* later invalidation affects it, so data requested before a write can never
|
|
12
|
+
* look fresh after that write, whether it was cached or still in flight.
|
|
13
|
+
*/
|
|
14
|
+
export class CacheGeneration {
|
|
15
|
+
#current = 0;
|
|
16
|
+
readonly #log: Array<{ affects: Affects; generation: number }> = [];
|
|
17
|
+
|
|
18
|
+
get current(): number {
|
|
19
|
+
return this.#current;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bump(affects: Affects): void {
|
|
23
|
+
this.#current += 1;
|
|
24
|
+
this.#log.push({ affects, generation: this.#current });
|
|
25
|
+
if (this.#log.length > MAX_TRACKED_INVALIDATIONS) {
|
|
26
|
+
this.#log.shift();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isFresh(href: string, snapshot: RouterState, since: number): boolean {
|
|
31
|
+
const [oldest] = this.#log;
|
|
32
|
+
if (oldest && since < oldest.generation - 1) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return !this.#log.some((entry) => entry.generation > since && entry.affects(href, snapshot));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
1
|
+
import { type Context, createContext, use, useCallback, useContext, useMemo } from "react";
|
|
2
2
|
import { navigationHrefPolicy, type RuntimeRouteTarget, resolveRouteTarget } from "./link-utils.ts";
|
|
3
3
|
import type {
|
|
4
4
|
NavigationOptions,
|
|
@@ -6,9 +6,24 @@ import type {
|
|
|
6
6
|
Router,
|
|
7
7
|
RouterContextValue,
|
|
8
8
|
RouterNavigate,
|
|
9
|
+
RouterStore,
|
|
10
|
+
StableRouter,
|
|
9
11
|
} from "./types.ts";
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// Duplicate module copies (separate entrypoints, client references) must share
|
|
14
|
+
// one context, or a Link rendered by another copy never sees the provider.
|
|
15
|
+
const ROUTER_CONTEXT = Symbol.for("furin.router.context.v1");
|
|
16
|
+
const ROUTER_STORE_CONTEXT = Symbol.for("furin.router.store.v1");
|
|
17
|
+
const contextGlobal = globalThis as typeof globalThis & {
|
|
18
|
+
[ROUTER_CONTEXT]?: Context<RouterContextValue | null>;
|
|
19
|
+
[ROUTER_STORE_CONTEXT]?: Context<RouterStore | null>;
|
|
20
|
+
};
|
|
21
|
+
/** Full router value; changes on every navigation, re-rendering every reader. */
|
|
22
|
+
export const RouterContext = (contextGlobal[ROUTER_CONTEXT] ??=
|
|
23
|
+
createContext<RouterContextValue | null>(null));
|
|
24
|
+
/** Stable counterpart of `RouterContext`, provided by `RouterProvider`. */
|
|
25
|
+
export const RouterStoreContext = (contextGlobal[ROUTER_STORE_CONTEXT] ??=
|
|
26
|
+
createContext<RouterStore | null>(null));
|
|
12
27
|
|
|
13
28
|
export const CLIENT_FALLBACK_ROUTER: RouterContextValue = {
|
|
14
29
|
basePath: "",
|
|
@@ -49,8 +64,23 @@ export function useRouterContext(): RouterContextValue {
|
|
|
49
64
|
return ctx ?? CLIENT_FALLBACK_ROUTER;
|
|
50
65
|
}
|
|
51
66
|
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
const subscribeNever = (_listener: () => void) => () => undefined;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the stable router handle. Outside `RouterProvider` (a bare
|
|
71
|
+
* `RouterContext.Provider`, or no provider at all) it wraps the plain context
|
|
72
|
+
* value, which is replaced rather than mutated, so it never notifies.
|
|
73
|
+
*/
|
|
74
|
+
export function useRouterStore(): RouterStore {
|
|
75
|
+
const store = use(RouterStoreContext);
|
|
76
|
+
if (store) {
|
|
77
|
+
return store;
|
|
78
|
+
}
|
|
79
|
+
const value = use(RouterContext) ?? CLIENT_FALLBACK_ROUTER;
|
|
80
|
+
return { getCurrentHref: () => value.currentHref, router: value, subscribe: subscribeNever };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function useTypedNavigation(context: StableRouter): Pick<Router, "navigate" | "prefetch"> {
|
|
54
84
|
const navigate: RouterNavigate = useCallback(
|
|
55
85
|
(next: string | (RuntimeRouteTarget & NavigationOptions), opts?: NavigationOptions) => {
|
|
56
86
|
const href = typeof next === "string" ? next : resolveRouteTarget(next, context.searchRoutes);
|
|
@@ -93,5 +123,11 @@ export function useRouter(): Router {
|
|
|
93
123
|
},
|
|
94
124
|
[context.prefetch, context.searchRoutes]
|
|
95
125
|
);
|
|
126
|
+
return { navigate, prefetch };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function useRouter(): Router {
|
|
130
|
+
const context = useRouterContext();
|
|
131
|
+
const { navigate, prefetch } = useTypedNavigation(context);
|
|
96
132
|
return useMemo(() => ({ ...context, navigate, prefetch }), [context, navigate, prefetch]);
|
|
97
133
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
type FetchObserver = (args: Parameters<typeof fetch>, response: Response) => void;
|
|
2
|
+
|
|
3
|
+
interface FetchPatch {
|
|
4
|
+
base: typeof fetch;
|
|
5
|
+
observers: Set<FetchObserver>;
|
|
6
|
+
patched: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const FETCH_PATCH = Symbol.for("furin.router.fetch-patch.v1");
|
|
10
|
+
const patchGlobal = globalThis as typeof globalThis & { [FETCH_PATCH]?: FetchPatch };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Observes every `window.fetch` response through one shared patch, so several
|
|
14
|
+
* mounted routers (or duplicate module copies) never overwrite or unwrap one
|
|
15
|
+
* another. The original fetch is restored when the last observer leaves, unless
|
|
16
|
+
* someone else replaced `window.fetch` in the meantime.
|
|
17
|
+
*/
|
|
18
|
+
export function observeWindowFetch(observer: FetchObserver): () => void {
|
|
19
|
+
let patch = patchGlobal[FETCH_PATCH];
|
|
20
|
+
if (!patch) {
|
|
21
|
+
const base = window.fetch;
|
|
22
|
+
const observers = new Set<FetchObserver>();
|
|
23
|
+
const patched = Object.assign(async (...args: Parameters<typeof fetch>) => {
|
|
24
|
+
const response = await base.apply(window, args);
|
|
25
|
+
for (const notify of observers) {
|
|
26
|
+
notify(args, response);
|
|
27
|
+
}
|
|
28
|
+
return response;
|
|
29
|
+
}, base);
|
|
30
|
+
patch = { base, observers, patched };
|
|
31
|
+
patchGlobal[FETCH_PATCH] = patch;
|
|
32
|
+
window.fetch = patched;
|
|
33
|
+
}
|
|
34
|
+
const active = patch;
|
|
35
|
+
active.observers.add(observer);
|
|
36
|
+
return () => {
|
|
37
|
+
active.observers.delete(observer);
|
|
38
|
+
if (active.observers.size > 0 || patchGlobal[FETCH_PATCH] !== active) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
patchGlobal[FETCH_PATCH] = undefined;
|
|
42
|
+
if (window.fetch === active.patched) {
|
|
43
|
+
window.fetch = active.base;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transactional refresh called by the generated `_hydrate.tsx` on HMR:
|
|
3
|
+
* `beforeCommit` swaps the hot component just before fresh data is published.
|
|
4
|
+
*/
|
|
5
|
+
export type HmrRefresh = (
|
|
6
|
+
beforeCommit: (() => void) | undefined,
|
|
7
|
+
dataChanged: boolean | undefined
|
|
8
|
+
) => Promise<void>;
|
|
9
|
+
|
|
10
|
+
const HMR_REFRESHES = Symbol.for("furin.router.hmr-refreshes.v1");
|
|
11
|
+
|
|
12
|
+
interface HmrWindow {
|
|
13
|
+
__FURIN_HMR_REFRESH__?: HmrRefresh;
|
|
14
|
+
[HMR_REFRESHES]?: Set<HmrRefresh>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Registers one router's HMR refresh. `window.__FURIN_HMR_REFRESH__` fans out
|
|
19
|
+
* to every mounted router, runs `beforeCommit` once (on the first commit), and
|
|
20
|
+
* is removed when the last router unmounts so `_hydrate.tsx` falls back to a
|
|
21
|
+
* full reload.
|
|
22
|
+
*/
|
|
23
|
+
export function registerHmrRefresh(refresh: HmrRefresh): () => void {
|
|
24
|
+
const hmrWindow = window as Window & HmrWindow;
|
|
25
|
+
let refreshes = hmrWindow[HMR_REFRESHES];
|
|
26
|
+
if (!refreshes) {
|
|
27
|
+
const registered = new Set<HmrRefresh>();
|
|
28
|
+
refreshes = registered;
|
|
29
|
+
hmrWindow[HMR_REFRESHES] = registered;
|
|
30
|
+
hmrWindow.__FURIN_HMR_REFRESH__ = async (beforeCommit, dataChanged) => {
|
|
31
|
+
let committed = false;
|
|
32
|
+
const commitOnce = () => {
|
|
33
|
+
if (!committed) {
|
|
34
|
+
committed = true;
|
|
35
|
+
beforeCommit?.();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
await Promise.all([...registered].map((handler) => handler(commitOnce, dataChanged)));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const active = refreshes;
|
|
42
|
+
active.add(refresh);
|
|
43
|
+
return () => {
|
|
44
|
+
active.delete(refresh);
|
|
45
|
+
if (active.size === 0 && hmrWindow[HMR_REFRESHES] === active) {
|
|
46
|
+
hmrWindow[HMR_REFRESHES] = undefined;
|
|
47
|
+
hmrWindow.__FURIN_HMR_REFRESH__ = undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noBarrelFile: client/router barrel — public surface of the SPA router
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
generateHistoryKey,
|
|
6
|
-
getHistoryKey,
|
|
7
|
-
isStaleDeployResponse,
|
|
8
|
-
SCROLL_STORAGE_KEY,
|
|
9
|
-
saveScrollPosition,
|
|
10
|
-
} from "./history.ts";
|
|
2
|
+
export { buildRouterTree } from "./boundary-tree.tsx";
|
|
3
|
+
export { RouterContext, useRouter } from "./context.ts";
|
|
11
4
|
export {
|
|
12
5
|
applyRevalidateHeader,
|
|
13
6
|
buildHref,
|
|
14
|
-
decodeHashFragment,
|
|
15
|
-
isSameOriginFetchResult,
|
|
16
|
-
navigationHrefPolicy,
|
|
17
7
|
normalizeHref,
|
|
18
|
-
normalizePath,
|
|
19
8
|
shouldAutoRefreshPath,
|
|
20
9
|
shouldInterceptClick,
|
|
21
10
|
shouldRefetch,
|
|
22
|
-
stripHashFromHref,
|
|
23
|
-
TRAILING_SLASHES_RE,
|
|
24
11
|
toLogical,
|
|
25
12
|
} from "./link-utils.ts";
|
|
26
13
|
export type { Navigate, NavigateInput } from "./navigation.ts";
|
|
27
14
|
export { useNavigate } from "./navigation.ts";
|
|
28
15
|
export { RouterProvider } from "./provider.tsx";
|
|
29
16
|
export type { SearchStore, SearchStoreSnapshot } from "./search-store.ts";
|
|
30
|
-
export {
|
|
31
|
-
createSearchStore,
|
|
32
|
-
FALLBACK_SEARCH_STORE,
|
|
33
|
-
SearchStoreContext,
|
|
34
|
-
searchSnapshotFromRouterContext,
|
|
35
|
-
} from "./search-store.ts";
|
|
36
|
-
export {
|
|
37
|
-
buildDataEndpoint,
|
|
38
|
-
buildNotFoundPageElement,
|
|
39
|
-
classifySpaResponse,
|
|
40
|
-
detectStaticMode,
|
|
41
|
-
parsePageResponse,
|
|
42
|
-
pickDeepestNotFound,
|
|
43
|
-
} from "./spa-response.ts";
|
|
17
|
+
export { buildDataEndpoint, classifySpaResponse, detectStaticMode } from "./spa-response.ts";
|
|
44
18
|
export type {
|
|
45
19
|
CacheEntry,
|
|
20
|
+
CheckedRouteTo,
|
|
46
21
|
ClientRoute,
|
|
47
22
|
ClientSegmentBoundary,
|
|
48
23
|
LinkProps,
|
|
@@ -52,12 +27,15 @@ export type {
|
|
|
52
27
|
RootBoundaryOptions,
|
|
53
28
|
RouteManifest,
|
|
54
29
|
RouteParamsOf,
|
|
30
|
+
RoutePattern,
|
|
31
|
+
RoutePatternOf,
|
|
55
32
|
Router,
|
|
56
33
|
RouterContextValue,
|
|
57
34
|
RouterNavigate,
|
|
58
35
|
RouterProviderProps,
|
|
59
36
|
RouterState,
|
|
60
37
|
RouteSearch,
|
|
38
|
+
RouteSearchOutput,
|
|
61
39
|
RouteTo,
|
|
62
40
|
SpaResponseKind,
|
|
63
41
|
} from "./types.ts";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { decodeInvalidationEntry, isInvalidatedPath } from "../../shared/invalidation-header.ts";
|
|
2
|
+
import { isWithinPrefix } from "../../shared/prefix.ts";
|
|
1
3
|
import {
|
|
2
4
|
buildSearchParams,
|
|
3
5
|
findSearchDefaultsForRouteTarget,
|
|
@@ -168,15 +170,11 @@ export function applyRevalidateEntries(
|
|
|
168
170
|
invalidate: (path: string, type: "page" | "layout" | undefined) => void
|
|
169
171
|
): void {
|
|
170
172
|
for (const entry of entries) {
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
173
|
+
const { path, type } = decodeInvalidationEntry(entry);
|
|
174
|
+
if (!path) {
|
|
173
175
|
continue;
|
|
174
176
|
}
|
|
175
|
-
|
|
176
|
-
invalidate(trimmed.slice(0, -":layout".length), "layout");
|
|
177
|
-
} else {
|
|
178
|
-
invalidate(trimmed, "page");
|
|
179
|
-
}
|
|
177
|
+
invalidate(path, type);
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
|
|
@@ -189,14 +187,15 @@ export function shouldAutoRefreshPath(
|
|
|
189
187
|
currentPath: string,
|
|
190
188
|
invalidations: ReadonlyArray<{ path: string; type: "page" | "layout" }>
|
|
191
189
|
): boolean {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
190
|
+
const normalize = (path: string) =>
|
|
191
|
+
path
|
|
192
|
+
.split("/")
|
|
193
|
+
.map((segment) => encodeURIComponent(decodeHashFragment(segment).toWellFormed()))
|
|
194
|
+
.join("/");
|
|
195
|
+
const normalizedCurrent = normalize(currentPath.split("?")[0] ?? currentPath);
|
|
196
|
+
return invalidations.some(({ path, type }) =>
|
|
197
|
+
isInvalidatedPath(normalizedCurrent, normalize(path), type)
|
|
198
|
+
);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
export function stripHashFromHref(href: string): string {
|
|
@@ -215,7 +214,7 @@ export function normalizeHref(href: string): string {
|
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
/** Strips a single trailing slash from a pathname. Root `/` and empty string are preserved. */
|
|
218
|
-
|
|
217
|
+
function normalizePath(path: string): string {
|
|
219
218
|
if (path === "/" || path === "") {
|
|
220
219
|
return path;
|
|
221
220
|
}
|
|
@@ -274,27 +273,16 @@ export function shouldInterceptClick(
|
|
|
274
273
|
return null;
|
|
275
274
|
}
|
|
276
275
|
|
|
277
|
-
|
|
278
|
-
const normalizedBase = normalizePath(basePath);
|
|
279
|
-
const normalizedPathname = normalizePath(url.pathname);
|
|
280
|
-
if (
|
|
281
|
-
normalizedBase &&
|
|
282
|
-
normalizedPathname !== normalizedBase &&
|
|
283
|
-
!normalizedPathname.startsWith(`${normalizedBase}/`)
|
|
284
|
-
) {
|
|
276
|
+
if (!isWithinPrefix(normalizePath(url.pathname), normalizePath(basePath))) {
|
|
285
277
|
return null;
|
|
286
278
|
}
|
|
287
|
-
return
|
|
279
|
+
return normalizeHref(toLogical(url.pathname, basePath)) + url.search + url.hash;
|
|
288
280
|
}
|
|
289
281
|
|
|
290
282
|
/** Strips basePath prefix from a physical pathname, returning the logical path. */
|
|
291
283
|
export function toLogical(physicalPathname: string, basePath: string): string {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
physicalPathname.startsWith(basePath) &&
|
|
295
|
-
// Require a path boundary after the prefix so "/furin" doesn't match "/furinity/foo"
|
|
296
|
-
(physicalPathname.length === basePath.length || physicalPathname[basePath.length] === "/")
|
|
297
|
-
) {
|
|
284
|
+
// The path boundary check keeps "/furin" from matching "/furinity/foo".
|
|
285
|
+
if (basePath && isWithinPrefix(physicalPathname, basePath)) {
|
|
298
286
|
return physicalPathname.slice(basePath.length) || "/";
|
|
299
287
|
}
|
|
300
288
|
return physicalPathname;
|