@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
|
@@ -59,6 +59,11 @@ export interface ChangePage {
|
|
|
59
59
|
}
|
|
60
60
|
export interface SyncAdapter {
|
|
61
61
|
abortMutation: (lease: MutationLease) => Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Journals invalidations no mutation lease owns (`invalidateSync()`, `idempotent: false`
|
|
64
|
+
* routes) and returns their cursor. Without explicit provenance, readers reset.
|
|
65
|
+
*/
|
|
66
|
+
appendInvalidations: (invalidations: readonly SyncInvalidation[], principal?: string) => Promise<string>;
|
|
62
67
|
beginMutation: (input: BeginMutationInput) => Promise<BeginMutationResult>;
|
|
63
68
|
completeMutation: (input: CompleteMutationInput) => Promise<CompleteMutationResult>;
|
|
64
69
|
currentCursor: () => Promise<string>;
|
|
@@ -108,8 +113,15 @@ export type SyncMutation<Adapter> = <T>(callback: (tx: SyncTransaction<Adapter>)
|
|
|
108
113
|
transactionMode: "sync";
|
|
109
114
|
} ? T extends PromiseLike<unknown> ? never : unknown : unknown)) => Promise<Awaited<T>>;
|
|
110
115
|
export interface SyncRuntimeOptions<Adapter extends SyncAdapter = SyncAdapter> {
|
|
111
|
-
|
|
116
|
+
/** Factories run once during runtime composition, never during AOT or on a request. */
|
|
117
|
+
adapter: Adapter | (() => Adapter);
|
|
112
118
|
notifier?: SyncNotifier;
|
|
119
|
+
/** Authenticate the request and return its verified identity, including for journal recovery. */
|
|
113
120
|
principal: (context: Context) => Promise<string> | string;
|
|
121
|
+
/**
|
|
122
|
+
* Server-only key (at least 32 characters) for HMAC-SHA256 principal hashes sent
|
|
123
|
+
* to browsers and stored in the journal. Use the same value on every node.
|
|
124
|
+
*/
|
|
125
|
+
secret?: string;
|
|
114
126
|
}
|
|
115
127
|
import type { Context } from "elysia";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Context, type Elysia } from "elysia";
|
|
2
2
|
import type { InvalidationInput } from "../auto-invalidate/types.ts";
|
|
3
3
|
import type { AtomicMutationResult, MutationLease, SyncInvalidation, TransactionalSyncAdapter } from "./adapter.ts";
|
|
4
|
-
import { type SyncInvalidationSelector } from "./queries.ts";
|
|
5
4
|
import type { ResolvedSyncRuntime } from "./runtime.ts";
|
|
6
5
|
type CommittedMutation = Extract<AtomicMutationResult<unknown>, {
|
|
7
6
|
kind: "committed";
|
|
@@ -10,7 +9,6 @@ interface Execution<Tx> {
|
|
|
10
9
|
adapter: TransactionalSyncAdapter<Tx, "async" | "sync">;
|
|
11
10
|
app: Elysia;
|
|
12
11
|
context: Context;
|
|
13
|
-
invalidate: SyncInvalidationSelector | undefined;
|
|
14
12
|
lease: MutationLease;
|
|
15
13
|
onCommit: (result: CommittedMutation) => void;
|
|
16
14
|
resolvedInvalidate?: InvalidationInput;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
1
2
|
import type { SyncRuntimeOptions } from "./adapter.ts";
|
|
2
3
|
export interface FurinSyncOptions extends SyncRuntimeOptions {
|
|
4
|
+
/** Optional application-owned validity of an authenticated event connection. */
|
|
5
|
+
connection?: (context: Context) => SyncConnectionLease | undefined | Promise<SyncConnectionLease | undefined>;
|
|
3
6
|
path?: string;
|
|
4
7
|
}
|
|
8
|
+
export interface SyncConnectionLease {
|
|
9
|
+
release: () => void;
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
}
|
|
5
12
|
export type FurinSyncOption = FurinSyncOptions | false;
|
|
6
13
|
export declare function resolveSyncPath(sync: FurinSyncOption | undefined): string | undefined;
|
|
7
14
|
/**
|
|
@@ -9,5 +16,4 @@ export declare function resolveSyncPath(sync: FurinSyncOption | undefined): stri
|
|
|
9
16
|
* into rendered HTML; the client prepends its own basePath before connecting.
|
|
10
17
|
*/
|
|
11
18
|
export declare function getSyncPath(): string | undefined;
|
|
12
|
-
export declare function runWithSyncPath<T>(path: string | undefined, fn: () => T): T;
|
|
13
19
|
export declare function syncRuntimeOptions(sync: FurinSyncOptions): SyncRuntimeOptions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import type { FurinSyncOptions } from "./config.ts";
|
|
3
|
+
export declare const LOCAL_SYNC_CONNECTION: unique symbol;
|
|
4
|
+
export interface LocalSyncRequest extends Request {
|
|
5
|
+
[LOCAL_SYNC_CONNECTION]?: (context: Context, sync: FurinSyncOptions) => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/** Principal resolvers reject signed-out requests by throwing or returning an empty identity. */
|
|
8
|
+
export declare function verifiedSyncPrincipal(sync: FurinSyncOptions, context: Context): Promise<string | undefined>;
|
|
9
|
+
/** Acquire asynchronously while allowing the transport to close before acquisition finishes. */
|
|
10
|
+
export declare function createSyncConnectionLifetime(sync: FurinSyncOptions, context: Context, changed: () => void): {
|
|
11
|
+
acquire(): Promise<void>;
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
@@ -7,8 +7,31 @@ import { sql as drizzleSql } from "drizzle-orm";
|
|
|
7
7
|
class MutationLeaseLost extends Error {
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
// src/server/sync/principal-journal.ts
|
|
11
|
+
var principalJournals = new WeakSet;
|
|
12
|
+
var changePrincipals = new WeakMap;
|
|
13
|
+
var principalSecrets = new WeakMap;
|
|
14
|
+
function sharePrincipalSecret(journal, owner) {
|
|
15
|
+
principalSecrets.set(journal, principalSecrets.get(owner));
|
|
16
|
+
}
|
|
17
|
+
function principalHash(adapter, principal) {
|
|
18
|
+
const secret = principalSecrets.get(adapter);
|
|
19
|
+
const hasher = secret === undefined ? new Bun.CryptoHasher("sha256") : new Bun.CryptoHasher("sha256", secret);
|
|
20
|
+
return hasher.update(principal).digest("hex");
|
|
21
|
+
}
|
|
22
|
+
function registerPrincipalJournal(adapter) {
|
|
23
|
+
principalJournals.add(adapter);
|
|
24
|
+
}
|
|
25
|
+
function journalChange(change, hash) {
|
|
26
|
+
if (hash !== undefined && hash !== null) {
|
|
27
|
+
changePrincipals.set(change, hash);
|
|
28
|
+
}
|
|
29
|
+
return change;
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
// src/server/sync/postgres/execute.ts
|
|
11
|
-
async function executePostgresMutation(journal, lease, tx, callback) {
|
|
33
|
+
async function executePostgresMutation(owner, journal, lease, tx, callback) {
|
|
34
|
+
sharePrincipalSecret(journal, owner);
|
|
12
35
|
if (!await journal.lockMutation(lease)) {
|
|
13
36
|
throw new MutationLeaseLost("[furin] Mutation lease lost; the transaction was rolled back.");
|
|
14
37
|
}
|
|
@@ -63,6 +86,7 @@ class PostgresSyncAdapter {
|
|
|
63
86
|
this.publishesNotifications = options.publishNotifications !== false;
|
|
64
87
|
this.namespace = options.namespace;
|
|
65
88
|
this.sql = options.sql;
|
|
89
|
+
registerPrincipalJournal(this);
|
|
66
90
|
}
|
|
67
91
|
beginMutation(input) {
|
|
68
92
|
return this.sql.begin(async (tx) => {
|
|
@@ -163,40 +187,7 @@ class PostgresSyncAdapter {
|
|
|
163
187
|
if (!await this.lockMutationInTransaction(tx, input.lease, checkExpiration)) {
|
|
164
188
|
return { kind: "lost" };
|
|
165
189
|
}
|
|
166
|
-
|
|
167
|
-
if (input.invalidations.length > 0) {
|
|
168
|
-
await tx`
|
|
169
|
-
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
170
|
-
VALUES (${this.namespace}, 0, 0)
|
|
171
|
-
ON CONFLICT (namespace) DO NOTHING
|
|
172
|
-
`;
|
|
173
|
-
const cursors = await tx`
|
|
174
|
-
UPDATE furin_sync.streams
|
|
175
|
-
SET current_cursor = current_cursor + 1
|
|
176
|
-
WHERE namespace = ${this.namespace}
|
|
177
|
-
RETURNING current_cursor
|
|
178
|
-
`;
|
|
179
|
-
cursor = String(cursors[0]?.current_cursor);
|
|
180
|
-
await tx`
|
|
181
|
-
INSERT INTO furin_sync.changes (namespace, cursor, invalidations)
|
|
182
|
-
VALUES (
|
|
183
|
-
${this.namespace},
|
|
184
|
-
${cursor},
|
|
185
|
-
${JSON.stringify(input.invalidations)}::text::jsonb
|
|
186
|
-
)
|
|
187
|
-
`;
|
|
188
|
-
await tx`
|
|
189
|
-
WITH removed AS (
|
|
190
|
-
DELETE FROM furin_sync.changes
|
|
191
|
-
WHERE namespace = ${this.namespace}
|
|
192
|
-
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
193
|
-
RETURNING cursor
|
|
194
|
-
)
|
|
195
|
-
UPDATE furin_sync.streams
|
|
196
|
-
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
197
|
-
WHERE namespace = ${this.namespace}
|
|
198
|
-
`;
|
|
199
|
-
}
|
|
190
|
+
const cursor = input.invalidations.length > 0 ? await this.appendChangeInTransaction(tx, input.invalidations, principalHash(this, input.lease.principal)) : undefined;
|
|
200
191
|
await tx`
|
|
201
192
|
UPDATE furin_sync.mutations
|
|
202
193
|
SET state = 'succeeded',
|
|
@@ -215,6 +206,50 @@ class PostgresSyncAdapter {
|
|
|
215
206
|
return { cursor, kind: "committed" };
|
|
216
207
|
});
|
|
217
208
|
}
|
|
209
|
+
appendInvalidations(invalidations, principal) {
|
|
210
|
+
return this.sql.begin(async (tx) => {
|
|
211
|
+
const cursor = await this.appendChangeInTransaction(tx, invalidations, principal === undefined ? null : principalHash(this, principal));
|
|
212
|
+
if (this.publishesNotifications) {
|
|
213
|
+
await tx.notify(this.notificationChannel, cursor);
|
|
214
|
+
}
|
|
215
|
+
return cursor;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async appendChangeInTransaction(tx, invalidations, principal) {
|
|
219
|
+
await tx`
|
|
220
|
+
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
221
|
+
VALUES (${this.namespace}, 0, 0)
|
|
222
|
+
ON CONFLICT (namespace) DO NOTHING
|
|
223
|
+
`;
|
|
224
|
+
const cursors = await tx`
|
|
225
|
+
UPDATE furin_sync.streams
|
|
226
|
+
SET current_cursor = current_cursor + 1
|
|
227
|
+
WHERE namespace = ${this.namespace}
|
|
228
|
+
RETURNING current_cursor
|
|
229
|
+
`;
|
|
230
|
+
const cursor = String(cursors[0]?.current_cursor);
|
|
231
|
+
await tx`
|
|
232
|
+
INSERT INTO furin_sync.changes (namespace, cursor, invalidations, principal_hash)
|
|
233
|
+
VALUES (
|
|
234
|
+
${this.namespace},
|
|
235
|
+
${cursor},
|
|
236
|
+
${JSON.stringify(invalidations)}::text::jsonb,
|
|
237
|
+
${principal}
|
|
238
|
+
)
|
|
239
|
+
`;
|
|
240
|
+
await tx`
|
|
241
|
+
WITH removed AS (
|
|
242
|
+
DELETE FROM furin_sync.changes
|
|
243
|
+
WHERE namespace = ${this.namespace}
|
|
244
|
+
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
245
|
+
RETURNING cursor
|
|
246
|
+
)
|
|
247
|
+
UPDATE furin_sync.streams
|
|
248
|
+
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
249
|
+
WHERE namespace = ${this.namespace}
|
|
250
|
+
`;
|
|
251
|
+
return cursor;
|
|
252
|
+
}
|
|
218
253
|
lockMutation(lease) {
|
|
219
254
|
return this.sql.begin((tx) => this.lockMutationInTransaction(tx, lease, true));
|
|
220
255
|
}
|
|
@@ -264,7 +299,7 @@ class PostgresSyncAdapter {
|
|
|
264
299
|
return { changes: [], cursor: currentCursor, hasMore: false, reset: true };
|
|
265
300
|
}
|
|
266
301
|
const rows = await this.sql`
|
|
267
|
-
SELECT cursor, invalidations
|
|
302
|
+
SELECT cursor, invalidations, principal_hash
|
|
268
303
|
FROM furin_sync.changes
|
|
269
304
|
WHERE namespace = ${this.namespace} AND cursor > ${input.after}::bigint
|
|
270
305
|
ORDER BY cursor ASC
|
|
@@ -285,10 +320,10 @@ class PostgresSyncAdapter {
|
|
|
285
320
|
};
|
|
286
321
|
}
|
|
287
322
|
const hasMore = rows.length > input.limit;
|
|
288
|
-
const changes = rows.slice(0, input.limit).map((row) => ({
|
|
323
|
+
const changes = rows.slice(0, input.limit).map((row) => journalChange({
|
|
289
324
|
cursor: String(row.cursor),
|
|
290
325
|
invalidations: row.invalidations
|
|
291
|
-
}));
|
|
326
|
+
}, row.principal_hash));
|
|
292
327
|
return {
|
|
293
328
|
changes,
|
|
294
329
|
cursor: changes.at(-1)?.cursor ?? input.after,
|
|
@@ -314,7 +349,7 @@ var LEASE_MS2 = 30000;
|
|
|
314
349
|
var MUTATION_TTL_MS2 = 24 * 60 * 60 * 1000;
|
|
315
350
|
var UNSIGNED_INTEGER_PATTERN2 = /^\d+$/;
|
|
316
351
|
function mutationKey2(input) {
|
|
317
|
-
return `${input.principal.length}:${input.principal}${input.key}
|
|
352
|
+
return new Bun.CryptoHasher("sha256").update(`${input.principal.length}:${input.principal}${input.key}`).digest("hex");
|
|
318
353
|
}
|
|
319
354
|
function storedResponse2(row) {
|
|
320
355
|
if (row.response_body === null || row.response_headers === null || row.response_status === null) {
|
|
@@ -336,6 +371,7 @@ class SqliteSyncAdapter {
|
|
|
336
371
|
}
|
|
337
372
|
this.database = options.database;
|
|
338
373
|
this.namespace = options.namespace;
|
|
374
|
+
registerPrincipalJournal(this);
|
|
339
375
|
this.scope = options.database.filename === "" || options.database.filename === ":memory:" ? "process-local" : "host-local";
|
|
340
376
|
}
|
|
341
377
|
async beginMutation(input) {
|
|
@@ -400,28 +436,7 @@ class SqliteSyncAdapter {
|
|
|
400
436
|
if (!this.hasMutationLeaseSync(completion.lease)) {
|
|
401
437
|
return { kind: "lost" };
|
|
402
438
|
}
|
|
403
|
-
|
|
404
|
-
if (completion.invalidations.length > 0) {
|
|
405
|
-
this.database.query(`INSERT INTO furin_sync_streams (namespace, current_cursor, oldest_cursor)
|
|
406
|
-
VALUES (?, 0, 0) ON CONFLICT (namespace) DO NOTHING`).run(this.namespace);
|
|
407
|
-
this.database.query(`UPDATE furin_sync_streams SET current_cursor = current_cursor + 1
|
|
408
|
-
WHERE namespace = ?`).run(this.namespace);
|
|
409
|
-
const cursorRow = this.database.query(`SELECT CAST(current_cursor AS TEXT) AS current_cursor
|
|
410
|
-
FROM furin_sync_streams WHERE namespace = ?`).get(this.namespace);
|
|
411
|
-
if (!cursorRow) {
|
|
412
|
-
throw new Error("[furin-sync-sqlite] Could not allocate a change cursor.");
|
|
413
|
-
}
|
|
414
|
-
cursor = cursorRow.current_cursor;
|
|
415
|
-
this.database.query(`INSERT INTO furin_sync_changes (namespace, cursor, invalidations, created_at)
|
|
416
|
-
VALUES (?, ?, ?, ?)`).run(this.namespace, cursorRow.current_cursor, JSON.stringify(completion.invalidations), now);
|
|
417
|
-
const removed = this.database.query(`DELETE FROM furin_sync_changes
|
|
418
|
-
WHERE namespace = ? AND cursor <= MAX(0, CAST(? AS INTEGER) - ?)`).run(this.namespace, cursorRow.current_cursor, CHANGE_RETENTION2);
|
|
419
|
-
if (removed.changes > 0) {
|
|
420
|
-
const oldest = this.database.query(`SELECT CAST(MIN(cursor) AS TEXT) AS cursor
|
|
421
|
-
FROM furin_sync_changes WHERE namespace = ?`).get(this.namespace);
|
|
422
|
-
this.database.query("UPDATE furin_sync_streams SET oldest_cursor = ? WHERE namespace = ?").run(oldest?.cursor ?? cursorRow.current_cursor, this.namespace);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
439
|
+
const cursor = completion.invalidations.length > 0 ? this.appendChangeSync(completion.invalidations, principalHash(this, completion.lease.principal)) : undefined;
|
|
425
440
|
this.database.query(`UPDATE furin_sync_mutations
|
|
426
441
|
SET state = 'succeeded', response_status = ?, response_headers = ?,
|
|
427
442
|
response_body = ?, completed_at = ?, expires_at = ?
|
|
@@ -430,6 +445,32 @@ class SqliteSyncAdapter {
|
|
|
430
445
|
});
|
|
431
446
|
return transaction.immediate(input);
|
|
432
447
|
}
|
|
448
|
+
async appendInvalidations(invalidations, principal) {
|
|
449
|
+
const hash = principal === undefined ? null : principalHash(this, principal);
|
|
450
|
+
return this.database.transaction(() => this.appendChangeSync(invalidations, hash)).immediate();
|
|
451
|
+
}
|
|
452
|
+
appendChangeSync(invalidations, principal) {
|
|
453
|
+
const now = Date.now();
|
|
454
|
+
this.database.query(`INSERT INTO furin_sync_streams (namespace, current_cursor, oldest_cursor)
|
|
455
|
+
VALUES (?, 0, 0) ON CONFLICT (namespace) DO NOTHING`).run(this.namespace);
|
|
456
|
+
this.database.query(`UPDATE furin_sync_streams SET current_cursor = current_cursor + 1
|
|
457
|
+
WHERE namespace = ?`).run(this.namespace);
|
|
458
|
+
const cursorRow = this.database.query(`SELECT CAST(current_cursor AS TEXT) AS current_cursor
|
|
459
|
+
FROM furin_sync_streams WHERE namespace = ?`).get(this.namespace);
|
|
460
|
+
if (!cursorRow) {
|
|
461
|
+
throw new Error("[furin-sync-sqlite] Could not allocate a change cursor.");
|
|
462
|
+
}
|
|
463
|
+
this.database.query(`INSERT INTO furin_sync_changes (namespace, cursor, invalidations, created_at, principal_hash)
|
|
464
|
+
VALUES (?, ?, ?, ?, ?)`).run(this.namespace, cursorRow.current_cursor, JSON.stringify(invalidations), now, principal);
|
|
465
|
+
const removed = this.database.query(`DELETE FROM furin_sync_changes
|
|
466
|
+
WHERE namespace = ? AND cursor <= MAX(0, CAST(? AS INTEGER) - ?)`).run(this.namespace, cursorRow.current_cursor, CHANGE_RETENTION2);
|
|
467
|
+
if (removed.changes > 0) {
|
|
468
|
+
const oldest = this.database.query(`SELECT CAST(MIN(cursor) AS TEXT) AS cursor
|
|
469
|
+
FROM furin_sync_changes WHERE namespace = ?`).get(this.namespace);
|
|
470
|
+
this.database.query("UPDATE furin_sync_streams SET oldest_cursor = ? WHERE namespace = ?").run(oldest?.cursor ?? cursorRow.current_cursor, this.namespace);
|
|
471
|
+
}
|
|
472
|
+
return cursorRow.current_cursor;
|
|
473
|
+
}
|
|
433
474
|
hasMutationLeaseSync(lease) {
|
|
434
475
|
return this.database.query(`SELECT mutation_id FROM furin_sync_mutations WHERE namespace = ? AND mutation_key = ? AND mutation_id = ? AND state = 'in-progress' AND lease_expires_at > ?`).get(this.namespace, mutationKey2(lease), lease.id, Date.now()) !== null;
|
|
435
476
|
}
|
|
@@ -454,13 +495,13 @@ class SqliteSyncAdapter {
|
|
|
454
495
|
if (!UNSIGNED_INTEGER_PATTERN2.test(page.after) || BigInt(page.after) > BigInt(currentCursor) || BigInt(page.after) < BigInt(cursorRow?.oldest_cursor ?? "0") - 1n) {
|
|
455
496
|
return { changes: [], cursor: currentCursor, hasMore: false, reset: true };
|
|
456
497
|
}
|
|
457
|
-
const rows = this.database.query(`SELECT CAST(cursor AS TEXT) AS cursor, invalidations FROM furin_sync_changes
|
|
498
|
+
const rows = this.database.query(`SELECT CAST(cursor AS TEXT) AS cursor, invalidations, principal_hash FROM furin_sync_changes
|
|
458
499
|
WHERE namespace = ? AND cursor > CAST(? AS INTEGER) ORDER BY cursor ASC LIMIT ?`).all(this.namespace, page.after, page.limit + 1);
|
|
459
500
|
const hasMore = rows.length > page.limit;
|
|
460
|
-
const changes = rows.slice(0, page.limit).map((row) => ({
|
|
501
|
+
const changes = rows.slice(0, page.limit).map((row) => journalChange({
|
|
461
502
|
cursor: row.cursor,
|
|
462
503
|
invalidations: JSON.parse(row.invalidations)
|
|
463
|
-
}));
|
|
504
|
+
}, row.principal_hash));
|
|
464
505
|
return {
|
|
465
506
|
changes,
|
|
466
507
|
cursor: changes.at(-1)?.cursor ?? page.after,
|
|
@@ -480,6 +521,10 @@ class SqliteSyncAdapter {
|
|
|
480
521
|
}
|
|
481
522
|
|
|
482
523
|
// src/server/sync/drizzle/index.ts
|
|
524
|
+
function drizzleTransactionSql(db) {
|
|
525
|
+
return transactionSql((strings, values) => Promise.resolve(db.execute(drizzleSql(strings, ...values))).then((rows) => rows));
|
|
526
|
+
}
|
|
527
|
+
|
|
483
528
|
class DrizzleSqliteSyncAdapter extends SqliteSyncAdapter {
|
|
484
529
|
transactionMode = "sync";
|
|
485
530
|
db;
|
|
@@ -510,16 +555,16 @@ class DrizzlePostgresSyncAdapter extends PostgresSyncAdapter {
|
|
|
510
555
|
db;
|
|
511
556
|
syncNamespace;
|
|
512
557
|
constructor(options) {
|
|
513
|
-
const sql =
|
|
514
|
-
sql.begin = (callback) => options.db.transaction((tx) => callback(
|
|
558
|
+
const sql = drizzleTransactionSql(options.db);
|
|
559
|
+
sql.begin = (callback) => options.db.transaction((tx) => callback(drizzleTransactionSql(tx)));
|
|
515
560
|
super({ namespace: options.namespace, sql, publishNotifications: false });
|
|
516
561
|
this.db = options.db;
|
|
517
562
|
this.syncNamespace = options.namespace;
|
|
518
563
|
}
|
|
519
564
|
executeMutation(lease, callback) {
|
|
520
565
|
return this.db.transaction((tx) => {
|
|
521
|
-
const sql =
|
|
522
|
-
return executePostgresMutation(new PostgresSyncAdapter({
|
|
566
|
+
const sql = drizzleTransactionSql(tx);
|
|
567
|
+
return executePostgresMutation(this, new PostgresSyncAdapter({
|
|
523
568
|
namespace: this.syncNamespace,
|
|
524
569
|
sql,
|
|
525
570
|
publishNotifications: false
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { invalidateSync as invalidateSyncImplementation } from "./invalidate-sync.ts";
|
|
2
2
|
import { PollingSyncNotifier as PollingSyncNotifierImplementation } from "./notifier.ts";
|
|
3
3
|
import { furinSync as furinSyncImplementation } from "./plugin.ts";
|
|
4
4
|
import { createSyncChangesPlugin as createSyncChangesPluginImplementation } from "./stream.ts";
|
|
5
5
|
export declare const createSyncChangesPlugin: typeof createSyncChangesPluginImplementation;
|
|
6
|
+
export type { SyncConnectionLease } from "./config.ts";
|
|
7
|
+
export { createLocalSyncClient, type LocalSyncClientOptions } from "./local-client.ts";
|
|
6
8
|
export declare const furinSync: typeof furinSyncImplementation;
|
|
7
|
-
export declare const
|
|
9
|
+
export declare const invalidateSync: typeof invalidateSyncImplementation;
|
|
10
|
+
export type { SyncInvalidationOptions } from "./invalidate-sync.ts";
|
|
8
11
|
export declare const PollingSyncNotifier: typeof PollingSyncNotifierImplementation;
|
|
9
|
-
export declare const resolveSyncPath: typeof resolveSyncPathImplementation;
|
|
10
|
-
export declare const runWithSyncPath: typeof runWithSyncPathImplementation;
|
|
11
12
|
export type PollingSyncNotifier = PollingSyncNotifierImplementation;
|
|
12
|
-
export type { SyncInvalidationInput } from "../auto-invalidate/types.ts";
|
|
13
13
|
export type { AtomicMutationResult, AtomicMutationValue, BeginMutationInput, BeginMutationResult, ChangePage, CompleteMutationInput, CompleteMutationResult, MutationLease, ReadChangesInput, StoredResponse, SyncAdapter, SyncChange, SyncInvalidation, SyncMutation, SyncNotifier, SyncRuntimeOptions, SyncSubscription, SyncTransaction, TransactionalSyncAdapter, } from "./adapter.ts";
|
|
14
14
|
export type { FurinSyncOption, FurinSyncOptions } from "./config.ts";
|
|
15
|
-
export type { SyncInput, SyncRouteOption } from "./plugin.ts";
|
|
16
15
|
export type { SyncChangePage } from "./stream.ts";
|