@teyik0/furin 0.7.0-alpha.3 → 0.9.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 +38 -1
- package/dist/adapter/build.d.ts +9 -0
- package/dist/adapter/bun/app.d.ts +1 -0
- package/dist/adapter/bun/server.d.ts +1 -0
- package/dist/adapter/bun.d.ts +9 -3
- package/dist/adapter/package.d.ts +1 -0
- package/dist/adapter/prerender.d.ts +21 -0
- package/dist/adapter/runtime-build.d.ts +31 -14
- 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/client.d.ts +2 -2
- 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/discover-pages-process.d.ts +1 -0
- package/dist/build/discover-pages.d.ts +11 -0
- package/dist/build/discovery-module.d.ts +3 -0
- package/dist/build/discovery-plugins.d.ts +34 -0
- package/dist/build/elysia-aot-worker.d.ts +4 -0
- package/dist/build/elysia-aot.d.ts +8 -2
- package/dist/build/entry-template.d.ts +14 -7
- package/dist/build/entry-template.ts +39 -19
- package/dist/build/hydrate.d.ts +17 -3
- package/dist/build/index.d.ts +7 -3
- package/dist/build/index.js +8852 -16175
- package/dist/build/preload-manifest.d.ts +2 -2
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/route-metadata.d.ts +31 -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 +5 -7
- package/dist/build/types.d.ts +27 -16
- package/dist/cache.js +117 -32
- package/dist/cli/config.d.ts +2 -2
- package/dist/cli/dev-worker.d.ts +1 -0
- package/dist/cli/dev-worker.ts +123 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/index.js +9104 -16086
- package/dist/client/browser-events-runtime.d.ts +2 -2
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/chunks/client-k29262a4.js +59 -0
- package/dist/client/chunks/client-k88668k7.js +159 -0
- package/dist/client/chunks/client-rjhxgt64.js +1035 -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/dev-error-overlay.ts +18 -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 +1738 -4184
- package/dist/client/mutation.d.ts +5 -0
- package/dist/client/query-store.d.ts +22 -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 +78 -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/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/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +7 -4
- package/dist/client/sync-client.d.ts +74 -0
- package/dist/client/sync.d.ts +43 -30
- package/dist/client.d.ts +3 -1
- package/dist/client.js +775 -937
- package/dist/config.d.ts +17 -13
- package/dist/config.js +3 -31
- package/dist/define-route.d.ts +262 -517
- package/dist/devtools/protocol.d.ts +4 -3
- package/dist/furin.d.ts +42 -31
- package/dist/furin.js +21464 -19101
- 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 +1757 -1218
- 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 +32 -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 +8 -4
- 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/server-only-module.d.ts +5 -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 +9852 -2088
- package/dist/server/lang-detect.d.ts +4 -4
- package/dist/server/logging/ingest-plugin.d.ts +31 -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 +1000 -731
- 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/server-entry.d.ts +5 -0
- package/dist/server/server-entry.js +36 -0
- package/dist/server/static-export.d.ts +38 -0
- package/dist/server/static-export.js +10777 -0
- package/dist/server/sync/adapter.d.ts +13 -1
- package/dist/server/sync/atomic.d.ts +0 -2
- package/dist/server/sync/config.d.ts +7 -1
- package/dist/server/sync/connection.d.ts +13 -0
- package/dist/server/sync/drizzle/index.js +113 -68
- package/dist/server/sync/fingerprint.d.ts +0 -1
- package/dist/server/sync/index.d.ts +5 -6
- package/dist/server/sync/index.js +2763 -1320
- package/dist/server/sync/invalidate-sync.d.ts +14 -0
- package/dist/server/sync/local-client.d.ts +9 -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 +50 -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 +8 -1
- package/dist/server/sync/sqlite/index.d.ts +3 -1
- package/dist/server/sync/sqlite/index.js +59 -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/browser-events.d.ts +4 -0
- 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/dist/sync-client.d.ts +3 -0
- package/dist/sync-client.js +1600 -0
- package/package.json +39 -23
- package/src/adapter/README.md +43 -15
- package/src/adapter/build.ts +270 -0
- package/src/adapter/bun/app.ts +5 -0
- package/src/adapter/bun/server.ts +14 -0
- package/src/adapter/bun.ts +104 -264
- package/src/adapter/furin-app.d.ts +15 -0
- package/src/adapter/package.ts +32 -27
- package/src/adapter/prerender.ts +97 -0
- package/src/adapter/runtime-build.ts +98 -102
- package/src/adapter/server-bundle.ts +110 -0
- package/src/adapter/static.ts +276 -260
- 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 +27 -63
- package/src/build/compile-entry.ts +1 -0
- package/src/build/discover-mounts-process.ts +17 -0
- package/src/build/discover-mounts.ts +40 -0
- package/src/build/discover-pages-process.ts +151 -0
- package/src/build/discover-pages.ts +69 -0
- package/src/build/discovery-module.ts +70 -0
- package/src/build/discovery-plugins.ts +101 -0
- package/src/build/elysia-aot-worker.ts +92 -9
- package/src/build/elysia-aot.ts +164 -70
- package/src/build/entry-template.ts +39 -19
- package/src/build/hydrate.ts +131 -50
- package/src/build/index.ts +136 -132
- package/src/build/preload-manifest.ts +3 -3
- package/src/build/private-server-sourcemaps.ts +5 -0
- package/src/build/production-instrumentation.ts +22 -19
- package/src/build/route-metadata.ts +90 -0
- package/src/build/route-types.ts +93 -11
- package/src/build/server-app-entry.ts +4 -21
- package/src/build/shared.ts +15 -49
- package/src/build/types.ts +23 -20
- package/src/build/virtual-entry.ts +2 -4
- package/src/cli/config.ts +137 -6
- package/src/cli/dev-worker.ts +123 -0
- package/src/cli/dev.ts +91 -0
- package/src/cli/index.ts +82 -21
- package/src/cli/preview.ts +2 -1
- package/src/client/boundaries.tsx +5 -14
- package/src/client/browser-events-runtime.ts +97 -23
- package/src/client/browser-events.ts +8 -0
- package/src/client/default-screens.tsx +2 -2
- package/src/client/define-route.ts +3 -2
- package/src/client/dev-error-overlay.ts +18 -1
- 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 +213 -31
- 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 +580 -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 +227 -1079
- package/src/client/router/search/index.ts +38 -14
- package/src/client/router/spa-response.ts +19 -70
- 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 +181 -0
- package/src/client/server-error.ts +2 -40
- package/src/client/sync-catch-up.ts +194 -0
- package/src/client/sync-client.ts +528 -0
- package/src/client/sync.ts +275 -378
- package/src/client.ts +10 -5
- package/src/config.ts +34 -49
- 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 +258 -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 +362 -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 +59 -34
- 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 +167 -26
- 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 +16 -19
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev/runtime.ts +404 -0
- package/src/server/dev/server-only-module.ts +23 -0
- package/src/server/dev/stack-location.ts +46 -0
- package/src/server/dev/symbolicate.ts +4 -3
- package/src/server/dev-page-imports.ts +185 -0
- package/src/server/dev-page-plugin.ts +57 -303
- 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/logging/ingest-plugin.ts +117 -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/server-entry.ts +39 -0
- package/src/server/static-export.ts +143 -0
- package/src/server/sync/adapter.ts +16 -1
- package/src/server/sync/atomic.ts +16 -36
- package/src/server/sync/config.ts +12 -14
- package/src/server/sync/connection.ts +71 -0
- package/src/server/sync/drizzle/index.ts +12 -20
- package/src/server/sync/fingerprint.ts +1 -1
- package/src/server/sync/index.ts +5 -10
- package/src/server/sync/invalidate-sync.ts +56 -0
- package/src/server/sync/local-client.ts +84 -0
- package/src/server/sync/mutation-handler.ts +6 -0
- package/src/server/sync/plugin.ts +193 -144
- package/src/server/sync/postgres/execute.ts +9 -1
- package/src/server/sync/postgres/index.ts +78 -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 +38 -6
- package/src/server/sync/redis/scripts.ts +10 -1
- package/src/server/sync/response.ts +47 -67
- package/src/server/sync/runtime.ts +74 -19
- package/src/server/sync/sqlite/index.ts +96 -61
- package/src/server/sync/sqlite/migration.sql +1 -0
- package/src/server/sync/stream.ts +62 -29
- 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/browser-events.ts +1 -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/src/sync-client.ts +14 -0
- 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/logger.d.ts +0 -4
- 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/client/router/sync-catch-up.ts +0 -120
- package/src/plugin/route-config-autofix.ts +0 -1149
- package/src/plugin/routes.ts +0 -1140
- package/src/server/logger.ts +0 -21
- package/src/server/router/hmr.production.ts +0 -18
|
@@ -70,35 +70,6 @@ function parseQueryFromURL(search: string, arrayKeys?: QueryKeyMap): UnknownObje
|
|
|
70
70
|
return query;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
* Parses the `?path=` argument of `/_furin/data`, rejecting absolute /
|
|
75
|
-
* protocol-relative inputs that would let a caller smuggle a foreign origin
|
|
76
|
-
* into the synthetic loader request.
|
|
77
|
-
*
|
|
78
|
-
* Returns `{ url, pathname }` on success, or `undefined` when the input is
|
|
79
|
-
* unsafe (the caller should reply 400). `new URL(rawPath, base)` ignores the
|
|
80
|
-
* base when `rawPath` is itself absolute, so without these prefix and origin
|
|
81
|
-
* checks a value like `https://evil.com/foo` would propagate to
|
|
82
|
-
* `syntheticRequest.url`.
|
|
83
|
-
*
|
|
84
|
-
* @internal Exported for unit testing.
|
|
85
|
-
*/
|
|
86
|
-
export function parseDataEndpointPath(rawPath: string): { url: URL; pathname: string } | undefined {
|
|
87
|
-
if (rawPath.includes("://") || rawPath.startsWith("//")) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
let url: URL;
|
|
91
|
-
try {
|
|
92
|
-
url = new URL(rawPath, "http://localhost");
|
|
93
|
-
} catch {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (url.origin !== "http://localhost") {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
return { pathname: url.pathname, url };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
73
|
function isObjectSchema(schema: unknown): schema is UnknownObject {
|
|
103
74
|
return !!schema && typeof schema === "object";
|
|
104
75
|
}
|
|
@@ -283,9 +254,8 @@ async function validateRouteInput(
|
|
|
283
254
|
}
|
|
284
255
|
|
|
285
256
|
/**
|
|
286
|
-
* Parses and validates a
|
|
287
|
-
*
|
|
288
|
-
* Elysia guard used by the full SSR route.
|
|
257
|
+
* Parses and validates a route URL's search string against the merged route
|
|
258
|
+
* chain schema, so SPA navigations and documents see the same query.
|
|
289
259
|
*
|
|
290
260
|
* @internal Exported for unit testing.
|
|
291
261
|
*/
|
|
@@ -308,9 +278,9 @@ export async function parseRouteQuery(
|
|
|
308
278
|
}
|
|
309
279
|
|
|
310
280
|
/**
|
|
311
|
-
* Validates and coerces path params
|
|
312
|
-
*
|
|
313
|
-
* the
|
|
281
|
+
* Validates and coerces path params against the merged route chain schema
|
|
282
|
+
* where Elysia has not already done so (the development shell, pages served
|
|
283
|
+
* through the not-found path).
|
|
314
284
|
*
|
|
315
285
|
* @internal Exported for unit testing.
|
|
316
286
|
*/
|
|
@@ -332,9 +302,6 @@ export function createSearchRouteMetadata(
|
|
|
332
302
|
const metadata: SearchRouteMetadata[] = [];
|
|
333
303
|
for (const route of routes) {
|
|
334
304
|
const searchDefaults = collectSearchDefaults(mergeRouteSchemas(route.routeChain, "query"));
|
|
335
|
-
if (!searchDefaults) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
305
|
metadata.push({
|
|
339
306
|
pattern: route.pattern,
|
|
340
307
|
regex: buildRouteRegex(route.pattern).regex,
|
|
@@ -346,7 +313,7 @@ export function createSearchRouteMetadata(
|
|
|
346
313
|
|
|
347
314
|
/**
|
|
348
315
|
* Applies top-level `default` values from a TypeBox TObject schema to a
|
|
349
|
-
* values record
|
|
316
|
+
* values record, so schema-validated route input sees the same
|
|
350
317
|
* defaulted query objects that the SSR path produces via Elysia's guard.
|
|
351
318
|
*/
|
|
352
319
|
export function applySchemaDefaults(
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { developmentGraphs, devGraph } from "../dev/graph.ts";
|
|
2
|
+
import { defaultInstanceBucket, scopedInstance } from "../instance.ts";
|
|
2
3
|
|
|
3
4
|
export function routeModuleSourceVersion(path: string): string {
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
5
|
+
// Bun's runtime plugin loads modules outside any runtime scope. Use the
|
|
6
|
+
// graphs whose routes depend on this source (or that have no snapshot yet)
|
|
7
|
+
// so an unrelated app's refresh cannot change its virtual identity.
|
|
8
|
+
const current = devGraph(scopedInstance() ?? defaultInstanceBucket());
|
|
8
9
|
const relevant = developmentGraphs().filter((graph) => {
|
|
9
10
|
const { snapshot } = graph;
|
|
10
11
|
return (
|
|
@@ -30,10 +30,8 @@ export interface SegmentBoundary {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface ResolvedRoute {
|
|
33
|
-
error?: ErrorComponent;
|
|
34
33
|
isrCache?: { html: string; generatedAt: number; revalidate: number };
|
|
35
34
|
mode: "ssr" | "ssg" | "isr";
|
|
36
|
-
notFound?: NotFoundComponent;
|
|
37
35
|
page: RuntimePage;
|
|
38
36
|
path: string;
|
|
39
37
|
pattern: string;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default mode for runtimes created afterwards and for code bound to no
|
|
3
|
+
* runtime (the default state bucket, standalone `furinSync()`). Each runtime
|
|
4
|
+
* fixes its own mode when `furin()` creates it (`FurinInstance.development`).
|
|
5
|
+
*/
|
|
1
6
|
export let IS_DEV = process.env.NODE_ENV !== "production";
|
|
2
7
|
|
|
3
|
-
/** @internal test-only —
|
|
8
|
+
/** @internal test-only — changes the default mode for runtimes created afterwards */
|
|
4
9
|
export function __setDevMode(val: boolean): void {
|
|
5
10
|
IS_DEV = val;
|
|
6
11
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AnyElysia, Elysia } from "elysia";
|
|
2
|
+
|
|
3
|
+
/** Normalize entry-owned listening without opening a socket or running startup hooks. */
|
|
4
|
+
export async function loadServerEntry<Module extends object>(
|
|
5
|
+
load: () => Promise<Module>
|
|
6
|
+
): Promise<Module & { default: AnyElysia }> {
|
|
7
|
+
const { listen } = Elysia.prototype;
|
|
8
|
+
let capturing = true;
|
|
9
|
+
let captured: AnyElysia | undefined;
|
|
10
|
+
Elysia.prototype.listen = function (this: AnyElysia, ...args) {
|
|
11
|
+
// desktopApp() can retain this method in its own listener wrapper. Once
|
|
12
|
+
// import finishes, that retained method must delegate to the real listener.
|
|
13
|
+
if (!capturing) {
|
|
14
|
+
return listen.apply(this, args);
|
|
15
|
+
}
|
|
16
|
+
if (captured && captured !== this) {
|
|
17
|
+
throw new Error("[furin] Server entry must listen on only one Elysia app.");
|
|
18
|
+
}
|
|
19
|
+
captured = this;
|
|
20
|
+
const [options] = args;
|
|
21
|
+
const serve = { ...this["~config"]?.serve };
|
|
22
|
+
Object.assign(serve, typeof options === "object" ? options : { port: Number(options) });
|
|
23
|
+
this["~config"] = { ...this["~config"], serve };
|
|
24
|
+
return this;
|
|
25
|
+
};
|
|
26
|
+
try {
|
|
27
|
+
const module = await load();
|
|
28
|
+
const app = (module as { default?: AnyElysia }).default ?? captured;
|
|
29
|
+
if (!app || typeof app.listen !== "function") {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"[furin] Server entry must export the Elysia app as default or call app.listen()."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return { ...module, default: app };
|
|
35
|
+
} finally {
|
|
36
|
+
capturing = false;
|
|
37
|
+
Elysia.prototype.listen = listen;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { RuntimeParams } from "../client/internal/runtime-types.ts";
|
|
2
|
+
import { mapWithConcurrency } from "../shared/utils/index.ts";
|
|
3
|
+
import { createInstance, withInstance } from "./instance.ts";
|
|
4
|
+
import { getCompileContext } from "./internal.ts";
|
|
5
|
+
import { prerenderSSG } from "./render/ssg.ts";
|
|
6
|
+
import { expandStaticPaths, type StaticPath } from "./render/static-params.ts";
|
|
7
|
+
import { setProductionPreloadManifest, setProductionTemplateContent } from "./render/template.ts";
|
|
8
|
+
import { loadProdRoutes } from "./router/discovery.ts";
|
|
9
|
+
import { buildRouteMatcher } from "./router/patterns.ts";
|
|
10
|
+
import { createSearchRouteMetadata } from "./router/schemas.ts";
|
|
11
|
+
import type { ResolvedRoute } from "./router/types.ts";
|
|
12
|
+
|
|
13
|
+
// Runs inside the temporary static-export bundle, in a child process: the
|
|
14
|
+
// build only receives serializable pages and writes them to disk itself.
|
|
15
|
+
|
|
16
|
+
/** Maximum concurrent staticParams() and render calls (mirrors warmSSGCache). */
|
|
17
|
+
const STATIC_CONCURRENCY = 4;
|
|
18
|
+
|
|
19
|
+
const STATIC_RENDER_ORIGIN = "http://localhost";
|
|
20
|
+
|
|
21
|
+
export interface StaticExportOptions {
|
|
22
|
+
basePath: string;
|
|
23
|
+
/** SSG route patterns the build validated as exportable. */
|
|
24
|
+
patterns: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface StaticExportPageBase {
|
|
28
|
+
params: RuntimeParams;
|
|
29
|
+
path: string;
|
|
30
|
+
pattern: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type StaticExportPage = StaticExportPageBase &
|
|
34
|
+
({ html: string; ndjson: string } | { redirect: string });
|
|
35
|
+
|
|
36
|
+
export interface StaticExportFailure {
|
|
37
|
+
/** Stack or message of the thrown value. */
|
|
38
|
+
error: string;
|
|
39
|
+
params: RuntimeParams | undefined;
|
|
40
|
+
path: string;
|
|
41
|
+
pattern: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface StaticExportResult {
|
|
45
|
+
/** Dynamic routes without staticParams(). */
|
|
46
|
+
missingParams: string[];
|
|
47
|
+
pages: StaticExportPage[];
|
|
48
|
+
/** Routes whose staticParams() threw (`path` is the pattern). */
|
|
49
|
+
paramsFailures: StaticExportFailure[];
|
|
50
|
+
renderFailures: StaticExportFailure[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function describeError(err: unknown): string {
|
|
54
|
+
return err instanceof Error ? (err.stack ?? err.message) : String(err);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function renderPage(
|
|
58
|
+
route: ResolvedRoute,
|
|
59
|
+
{ params, path }: StaticPath,
|
|
60
|
+
render: () => ReturnType<typeof prerenderSSG>
|
|
61
|
+
): Promise<StaticExportPage | StaticExportFailure> {
|
|
62
|
+
const base = { params, path, pattern: route.pattern };
|
|
63
|
+
try {
|
|
64
|
+
const entry = await render();
|
|
65
|
+
if (!(entry instanceof Response)) {
|
|
66
|
+
return { ...base, html: entry.html, ndjson: entry.ndjson };
|
|
67
|
+
}
|
|
68
|
+
const location = entry.headers.get("location");
|
|
69
|
+
if (entry.status < 300 || entry.status >= 400 || location === null) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`[furin] static: route "${route.pattern}" returned a response that cannot be exported.`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return { ...base, redirect: location };
|
|
75
|
+
} catch (err) {
|
|
76
|
+
return { ...base, error: describeError(err) };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Expands staticParams() and renders every exportable page of the sole
|
|
82
|
+
* compiled app, in a private runtime primed with the static shell.
|
|
83
|
+
*/
|
|
84
|
+
export async function exportStaticPages(options: StaticExportOptions): Promise<StaticExportResult> {
|
|
85
|
+
const ctx = getCompileContext();
|
|
86
|
+
if (ctx?.templateHtml === undefined) {
|
|
87
|
+
throw new Error("[furin] static: the export bundle registered no static shell.");
|
|
88
|
+
}
|
|
89
|
+
const { root, routes } = loadProdRoutes(ctx);
|
|
90
|
+
const runtime = createInstance("", ctx.rootPath.slice(0, ctx.rootPath.lastIndexOf("/")));
|
|
91
|
+
setProductionTemplateContent(ctx.templateHtml, runtime);
|
|
92
|
+
if (ctx.preloadManifest) {
|
|
93
|
+
setProductionPreloadManifest(ctx.preloadManifest, runtime);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ssgRoutes = routes.filter((route) => options.patterns.includes(route.pattern));
|
|
97
|
+
const searchRoutes = createSearchRouteMetadata(ssgRoutes);
|
|
98
|
+
// Ownership is decided against every route, exported or not, so a
|
|
99
|
+
// staticParams() value never overwrites the page of a more specific route.
|
|
100
|
+
const matchRoute = buildRouteMatcher(routes);
|
|
101
|
+
const result: StaticExportResult = {
|
|
102
|
+
missingParams: [],
|
|
103
|
+
pages: [],
|
|
104
|
+
paramsFailures: [],
|
|
105
|
+
renderFailures: [],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
await withInstance(runtime, async () => {
|
|
109
|
+
const expanded = await mapWithConcurrency(ssgRoutes, STATIC_CONCURRENCY, async (route) => {
|
|
110
|
+
try {
|
|
111
|
+
return { paths: await expandStaticPaths(route, matchRoute, STATIC_RENDER_ORIGIN), route };
|
|
112
|
+
} catch (err) {
|
|
113
|
+
result.paramsFailures.push({
|
|
114
|
+
error: describeError(err),
|
|
115
|
+
params: undefined,
|
|
116
|
+
path: route.pattern,
|
|
117
|
+
pattern: route.pattern,
|
|
118
|
+
});
|
|
119
|
+
return { paths: [], route };
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const tasks = expanded.flatMap(({ paths, route }) => {
|
|
123
|
+
if (paths === undefined) {
|
|
124
|
+
result.missingParams.push(route.pattern);
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return paths.map((path) => ({ path, route }));
|
|
128
|
+
});
|
|
129
|
+
const rendered = await mapWithConcurrency(tasks, STATIC_CONCURRENCY, ({ path, route }) =>
|
|
130
|
+
renderPage(route, path, () =>
|
|
131
|
+
prerenderSSG(route, path.params, root, STATIC_RENDER_ORIGIN, options.basePath, searchRoutes)
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
for (const page of rendered) {
|
|
135
|
+
if ("error" in page) {
|
|
136
|
+
result.renderFailures.push(page);
|
|
137
|
+
} else {
|
|
138
|
+
result.pages.push(page);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
@@ -55,6 +55,14 @@ export interface ChangePage {
|
|
|
55
55
|
|
|
56
56
|
export interface SyncAdapter {
|
|
57
57
|
abortMutation: (lease: MutationLease) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Journals invalidations no mutation lease owns (`invalidateSync()`, `idempotent: false`
|
|
60
|
+
* routes) and returns their cursor. Without explicit provenance, readers reset.
|
|
61
|
+
*/
|
|
62
|
+
appendInvalidations: (
|
|
63
|
+
invalidations: readonly SyncInvalidation[],
|
|
64
|
+
principal?: string
|
|
65
|
+
) => Promise<string>;
|
|
58
66
|
beginMutation: (input: BeginMutationInput) => Promise<BeginMutationResult>;
|
|
59
67
|
completeMutation: (input: CompleteMutationInput) => Promise<CompleteMutationResult>;
|
|
60
68
|
currentCursor: () => Promise<string>;
|
|
@@ -123,9 +131,16 @@ export type SyncMutation<Adapter> = <T>(
|
|
|
123
131
|
) => Promise<Awaited<T>>;
|
|
124
132
|
|
|
125
133
|
export interface SyncRuntimeOptions<Adapter extends SyncAdapter = SyncAdapter> {
|
|
126
|
-
|
|
134
|
+
/** Factories run once during runtime composition, never during AOT or on a request. */
|
|
135
|
+
adapter: Adapter | (() => Adapter);
|
|
127
136
|
notifier?: SyncNotifier;
|
|
137
|
+
/** Authenticate the request and return its verified identity, including for journal recovery. */
|
|
128
138
|
principal: (context: Context) => Promise<string> | string;
|
|
139
|
+
/**
|
|
140
|
+
* Server-only key (at least 32 characters) for HMAC-SHA256 principal hashes sent
|
|
141
|
+
* to browsers and stored in the journal. Use the same value on every node.
|
|
142
|
+
*/
|
|
143
|
+
secret?: string;
|
|
129
144
|
}
|
|
130
145
|
|
|
131
146
|
import type { Context } from "elysia";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { type Context, type Elysia, ElysiaStatus,
|
|
1
|
+
import { type Context, type Elysia, ElysiaStatus, Validator } from "elysia";
|
|
2
|
+
import {
|
|
3
|
+
decodeInvalidationEntry,
|
|
4
|
+
encodeInvalidationEntry,
|
|
5
|
+
serializeInvalidationPaths,
|
|
6
|
+
} from "../../shared/invalidation-header.ts";
|
|
2
7
|
import {
|
|
3
8
|
appendPendingInvalidationHeader,
|
|
4
9
|
runInvalidationRules,
|
|
@@ -12,12 +17,10 @@ import type {
|
|
|
12
17
|
SyncInvalidation,
|
|
13
18
|
TransactionalSyncAdapter,
|
|
14
19
|
} from "./adapter.ts";
|
|
20
|
+
import { appendQueryInvalidations, resolveSyncInvalidations } from "./queries.ts";
|
|
15
21
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
type SyncInvalidationSelector,
|
|
19
|
-
} from "./queries.ts";
|
|
20
|
-
import {
|
|
22
|
+
effectiveResponseHeaders,
|
|
23
|
+
effectiveResponseStatus,
|
|
21
24
|
mergeStoredResponseHeaders,
|
|
22
25
|
type StoreResponseResult,
|
|
23
26
|
storeResponse,
|
|
@@ -42,26 +45,12 @@ interface Execution<Tx> {
|
|
|
42
45
|
adapter: TransactionalSyncAdapter<Tx, "async" | "sync">;
|
|
43
46
|
app: Elysia;
|
|
44
47
|
context: Context;
|
|
45
|
-
invalidate: SyncInvalidationSelector | undefined;
|
|
46
48
|
lease: MutationLease;
|
|
47
49
|
onCommit: (result: CommittedMutation) => void;
|
|
48
50
|
resolvedInvalidate?: InvalidationInput;
|
|
49
51
|
runtime: ResolvedSyncRuntime;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function responseStatus(context: Context, value: unknown): number {
|
|
53
|
-
if (value instanceof Response && value.status !== 200) {
|
|
54
|
-
return value.status;
|
|
55
|
-
}
|
|
56
|
-
if (value instanceof ElysiaStatus) {
|
|
57
|
-
return value.status;
|
|
58
|
-
}
|
|
59
|
-
if (typeof context.set.status === "string") {
|
|
60
|
-
return StatusMap[context.set.status];
|
|
61
|
-
}
|
|
62
|
-
return context.set.status ?? 200;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
54
|
function withStatus(original: unknown, value: unknown): unknown {
|
|
66
55
|
return original instanceof ElysiaStatus
|
|
67
56
|
? new ElysiaStatus(original.status, value, original.headers)
|
|
@@ -113,7 +102,7 @@ function validateResult<Tx>(execution: Execution<Tx>, value: unknown): unknown {
|
|
|
113
102
|
schema.response ? [schema.response] : []
|
|
114
103
|
),
|
|
115
104
|
});
|
|
116
|
-
const validator = validators?.
|
|
105
|
+
const validator = validators?.get(effectiveResponseStatus(value, context.set));
|
|
117
106
|
if (!validator) {
|
|
118
107
|
return value;
|
|
119
108
|
}
|
|
@@ -135,11 +124,11 @@ function validateResult<Tx>(execution: Execution<Tx>, value: unknown): unknown {
|
|
|
135
124
|
|
|
136
125
|
function prepare<Tx>(execution: Execution<Tx>, value: unknown, original: unknown) {
|
|
137
126
|
const { context } = execution;
|
|
138
|
-
const status =
|
|
127
|
+
const status = effectiveResponseStatus(value, context.set);
|
|
139
128
|
if (status < 200 || status >= 400) {
|
|
140
129
|
throw new RejectedMutation(original);
|
|
141
130
|
}
|
|
142
|
-
const invalidate = resolveSyncInvalidations(
|
|
131
|
+
const invalidate = resolveSyncInvalidations(context);
|
|
143
132
|
execution.resolvedInvalidate = invalidate;
|
|
144
133
|
appendQueryInvalidations(invalidate, context);
|
|
145
134
|
const invalidations = [
|
|
@@ -151,9 +140,9 @@ function prepare<Tx>(execution: Execution<Tx>, value: unknown, original: unknown
|
|
|
151
140
|
}
|
|
152
141
|
const paths = invalidations
|
|
153
142
|
.filter((entry): entry is Extract<SyncInvalidation, { kind: "path" }> => entry.kind === "path")
|
|
154
|
-
.map((entry) => (entry.
|
|
143
|
+
.map((entry) => encodeInvalidationEntry(entry.path, entry.type));
|
|
155
144
|
if (paths.length > 0) {
|
|
156
|
-
context.set.headers["x-furin-revalidate"] = paths
|
|
145
|
+
context.set.headers["x-furin-revalidate"] = serializeInvalidationPaths(paths);
|
|
157
146
|
}
|
|
158
147
|
const finish = (stored: StoreResponseResult) => {
|
|
159
148
|
if (stored.kind === "unreplayable") {
|
|
@@ -161,12 +150,7 @@ function prepare<Tx>(execution: Execution<Tx>, value: unknown, original: unknown
|
|
|
161
150
|
"[furin] Atomic mutation responses must be bounded JSON, text or bodyless responses."
|
|
162
151
|
);
|
|
163
152
|
}
|
|
164
|
-
|
|
165
|
-
if (value instanceof ElysiaStatus) {
|
|
166
|
-
headers = { ...headers, ...value.headers };
|
|
167
|
-
} else if (value instanceof Response) {
|
|
168
|
-
headers = { ...headers, ...Object.fromEntries(value.headers) };
|
|
169
|
-
}
|
|
153
|
+
const headers = effectiveResponseHeaders(value, context.set);
|
|
170
154
|
return {
|
|
171
155
|
invalidations,
|
|
172
156
|
response: mergeStoredResponseHeaders({ ...stored.response, status }, headers),
|
|
@@ -295,9 +279,5 @@ export function normalizedInvalidations(input: InvalidationInput | undefined): S
|
|
|
295
279
|
export function pendingPathInvalidations(
|
|
296
280
|
entries: readonly string[]
|
|
297
281
|
): Extract<SyncInvalidation, { kind: "path" }>[] {
|
|
298
|
-
return entries.map((entry) =>
|
|
299
|
-
entry.endsWith(":layout")
|
|
300
|
-
? { kind: "path" as const, path: entry.slice(0, -":layout".length), type: "layout" }
|
|
301
|
-
: { kind: "path" as const, path: entry, type: "page" }
|
|
302
|
-
);
|
|
282
|
+
return entries.map((entry) => ({ kind: "path" as const, ...decodeInvalidationEntry(entry) }));
|
|
303
283
|
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
2
|
import { currentInstance } from "../instance.ts";
|
|
3
3
|
import type { SyncRuntimeOptions } from "./adapter.ts";
|
|
4
4
|
|
|
5
5
|
const SYNC_DEFAULT_PATH = "/_furin/sync";
|
|
6
6
|
|
|
7
|
-
// Explicit override scope (tests, synthetic renders). When unset, the sync
|
|
8
|
-
// path comes from the current furin instance.
|
|
9
|
-
const requestSyncPath = new AsyncLocalStorage<string | undefined>();
|
|
10
|
-
|
|
11
7
|
export interface FurinSyncOptions extends SyncRuntimeOptions {
|
|
8
|
+
/** Optional application-owned validity of an authenticated event connection. */
|
|
9
|
+
connection?: (
|
|
10
|
+
context: Context
|
|
11
|
+
) => SyncConnectionLease | undefined | Promise<SyncConnectionLease | undefined>;
|
|
12
12
|
path?: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export interface SyncConnectionLease {
|
|
16
|
+
release: () => void;
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
export type FurinSyncOption = FurinSyncOptions | false;
|
|
16
21
|
|
|
17
22
|
export function resolveSyncPath(sync: FurinSyncOption | undefined): string | undefined {
|
|
@@ -26,17 +31,10 @@ export function resolveSyncPath(sync: FurinSyncOption | undefined): string | und
|
|
|
26
31
|
* into rendered HTML; the client prepends its own basePath before connecting.
|
|
27
32
|
*/
|
|
28
33
|
export function getSyncPath(): string | undefined {
|
|
29
|
-
const override = requestSyncPath.getStore();
|
|
30
|
-
if (override !== undefined) {
|
|
31
|
-
return override;
|
|
32
|
-
}
|
|
33
34
|
return currentInstance().syncPath;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export function runWithSyncPath<T>(path: string | undefined, fn: () => T): T {
|
|
37
|
-
return requestSyncPath.run(path, fn);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
37
|
export function syncRuntimeOptions(sync: FurinSyncOptions): SyncRuntimeOptions {
|
|
41
|
-
|
|
38
|
+
// Preserve the identity shared by mutation and transport plugins.
|
|
39
|
+
return sync;
|
|
42
40
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import { log } from "evlog";
|
|
3
|
+
import type { FurinSyncOptions, SyncConnectionLease } from "./config.ts";
|
|
4
|
+
|
|
5
|
+
// A function on a Request never crosses HTTP; Symbol.for also works across published bundles.
|
|
6
|
+
export const LOCAL_SYNC_CONNECTION = Symbol.for("furin.sync.local-connection.v1");
|
|
7
|
+
export interface LocalSyncRequest extends Request {
|
|
8
|
+
[LOCAL_SYNC_CONNECTION]?: (context: Context, sync: FurinSyncOptions) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Principal resolvers reject signed-out requests by throwing or returning an empty identity. */
|
|
12
|
+
export async function verifiedSyncPrincipal(
|
|
13
|
+
sync: FurinSyncOptions,
|
|
14
|
+
context: Context
|
|
15
|
+
): Promise<string | undefined> {
|
|
16
|
+
try {
|
|
17
|
+
const principal = await sync.principal(context);
|
|
18
|
+
return principal.length > 0 ? principal : undefined;
|
|
19
|
+
} catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function releaseLease(lease: SyncConnectionLease | undefined): void {
|
|
25
|
+
try {
|
|
26
|
+
lease?.release();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
log.warn({ action: "sync_connection_release_failed", error: String(error) });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Acquire asynchronously while allowing the transport to close before acquisition finishes. */
|
|
33
|
+
export function createSyncConnectionLifetime(
|
|
34
|
+
sync: FurinSyncOptions,
|
|
35
|
+
context: Context,
|
|
36
|
+
changed: () => void
|
|
37
|
+
) {
|
|
38
|
+
let closed = false;
|
|
39
|
+
let lease: SyncConnectionLease | undefined;
|
|
40
|
+
const onAbort = () => {
|
|
41
|
+
if (!closed) {
|
|
42
|
+
changed();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
async acquire(): Promise<void> {
|
|
47
|
+
if (closed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const acquired = await sync.connection?.(context);
|
|
51
|
+
if (closed) {
|
|
52
|
+
releaseLease(acquired);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
lease = acquired;
|
|
56
|
+
lease?.signal.addEventListener("abort", onAbort, { once: true });
|
|
57
|
+
if (lease?.signal.aborted) {
|
|
58
|
+
onAbort();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
close(): void {
|
|
62
|
+
if (closed) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
closed = true;
|
|
66
|
+
lease?.signal.removeEventListener("abort", onAbort);
|
|
67
|
+
releaseLease(lease);
|
|
68
|
+
lease = undefined;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -21,6 +21,14 @@ type Transaction<Db extends BunSQLiteDatabase<Schema> | BunSQLDatabase<Schema>>
|
|
|
21
21
|
Parameters<Db["transaction"]>[0]
|
|
22
22
|
>[0];
|
|
23
23
|
|
|
24
|
+
function drizzleTransactionSql(db: Pick<BunSQLDatabase<Schema>, "execute">) {
|
|
25
|
+
return transactionSql(<Rows>(strings: TemplateStringsArray, values: unknown[]) =>
|
|
26
|
+
Promise.resolve(db.execute(drizzleSql(strings, ...values))).then(
|
|
27
|
+
(rows) => rows as unknown as Rows
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
export class DrizzleSqliteSyncAdapter<Db extends BunSQLiteDatabase<Schema>>
|
|
25
33
|
extends SqliteSyncAdapter
|
|
26
34
|
implements TransactionalSyncAdapter<Transaction<Db>, "sync">
|
|
@@ -71,21 +79,8 @@ export class DrizzlePostgresSyncAdapter<Db extends BunSQLDatabase<Schema>>
|
|
|
71
79
|
private readonly syncNamespace: string;
|
|
72
80
|
|
|
73
81
|
constructor(options: { db: Db & { $client: import("bun").SQL }; namespace: string }) {
|
|
74
|
-
const sql =
|
|
75
|
-
|
|
76
|
-
(rows) => rows as unknown as Rows
|
|
77
|
-
)
|
|
78
|
-
);
|
|
79
|
-
sql.begin = (callback) =>
|
|
80
|
-
options.db.transaction((tx) =>
|
|
81
|
-
callback(
|
|
82
|
-
transactionSql(<Rows>(strings: TemplateStringsArray, values: unknown[]) =>
|
|
83
|
-
Promise.resolve(tx.execute(drizzleSql(strings, ...values))).then(
|
|
84
|
-
(rows) => rows as unknown as Rows
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
)
|
|
88
|
-
);
|
|
82
|
+
const sql = drizzleTransactionSql(options.db);
|
|
83
|
+
sql.begin = (callback) => options.db.transaction((tx) => callback(drizzleTransactionSql(tx)));
|
|
89
84
|
super({ namespace: options.namespace, sql, publishNotifications: false });
|
|
90
85
|
this.db = options.db;
|
|
91
86
|
this.syncNamespace = options.namespace;
|
|
@@ -96,12 +91,9 @@ export class DrizzlePostgresSyncAdapter<Db extends BunSQLDatabase<Schema>>
|
|
|
96
91
|
callback: (tx: Transaction<Db>) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>
|
|
97
92
|
): Promise<AtomicMutationResult<T>> {
|
|
98
93
|
return this.db.transaction((tx) => {
|
|
99
|
-
const sql =
|
|
100
|
-
Promise.resolve(tx.execute(drizzleSql(strings, ...values))).then(
|
|
101
|
-
(rows) => rows as unknown as Rows
|
|
102
|
-
)
|
|
103
|
-
);
|
|
94
|
+
const sql = drizzleTransactionSql(tx);
|
|
104
95
|
return executePostgresMutation(
|
|
96
|
+
this,
|
|
105
97
|
new PostgresSyncAdapter({
|
|
106
98
|
namespace: this.syncNamespace,
|
|
107
99
|
sql,
|
|
@@ -24,7 +24,7 @@ function canonicalize(value: unknown): unknown {
|
|
|
24
24
|
return value;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
function sha256Hex(source: string): string {
|
|
28
28
|
const hasher = new Bun.CryptoHasher("sha256");
|
|
29
29
|
hasher.update(source);
|
|
30
30
|
return hasher.digest("hex");
|
package/src/server/sync/index.ts
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noBarrelFile: sync has a small public/internal surface
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
getSyncPath as getSyncPathImplementation,
|
|
5
|
-
resolveSyncPath as resolveSyncPathImplementation,
|
|
6
|
-
runWithSyncPath as runWithSyncPathImplementation,
|
|
7
|
-
} from "./config.ts";
|
|
3
|
+
import { invalidateSync as invalidateSyncImplementation } from "./invalidate-sync.ts";
|
|
8
4
|
import { PollingSyncNotifier as PollingSyncNotifierImplementation } from "./notifier.ts";
|
|
9
5
|
import { furinSync as furinSyncImplementation } from "./plugin.ts";
|
|
10
6
|
import { createSyncChangesPlugin as createSyncChangesPluginImplementation } from "./stream.ts";
|
|
11
7
|
|
|
12
8
|
export const createSyncChangesPlugin = createSyncChangesPluginImplementation;
|
|
9
|
+
export type { SyncConnectionLease } from "./config.ts";
|
|
10
|
+
export { createLocalSyncClient, type LocalSyncClientOptions } from "./local-client.ts";
|
|
13
11
|
export const furinSync = furinSyncImplementation;
|
|
14
|
-
export const
|
|
12
|
+
export const invalidateSync = invalidateSyncImplementation;
|
|
13
|
+
export type { SyncInvalidationOptions } from "./invalidate-sync.ts";
|
|
15
14
|
export const PollingSyncNotifier = PollingSyncNotifierImplementation;
|
|
16
|
-
export const resolveSyncPath = resolveSyncPathImplementation;
|
|
17
|
-
export const runWithSyncPath = runWithSyncPathImplementation;
|
|
18
15
|
|
|
19
16
|
export type PollingSyncNotifier = PollingSyncNotifierImplementation;
|
|
20
17
|
|
|
21
|
-
export type { SyncInvalidationInput } from "../auto-invalidate/types.ts";
|
|
22
18
|
export type {
|
|
23
19
|
AtomicMutationResult,
|
|
24
20
|
AtomicMutationValue,
|
|
@@ -41,5 +37,4 @@ export type {
|
|
|
41
37
|
TransactionalSyncAdapter,
|
|
42
38
|
} from "./adapter.ts";
|
|
43
39
|
export type { FurinSyncOption, FurinSyncOptions } from "./config.ts";
|
|
44
|
-
export type { SyncInput, SyncRouteOption } from "./plugin.ts";
|
|
45
40
|
export type { SyncChangePage } from "./stream.ts";
|