@teyik0/furin 0.7.0-alpha.3 → 0.8.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapter/build.d.ts +9 -0
- package/dist/adapter/bun/server.d.ts +1 -0
- package/dist/adapter/bun.d.ts +7 -3
- package/dist/adapter/package.d.ts +1 -0
- package/dist/adapter/prerender.d.ts +21 -0
- package/dist/adapter/runtime-build.d.ts +24 -10
- package/dist/adapter/server-bundle.d.ts +20 -0
- package/dist/adapter/static.d.ts +2 -2
- package/dist/adapter/types.d.ts +81 -0
- package/dist/adapter/vercel/bootstrap.d.ts +5 -0
- package/dist/adapter/vercel/data.d.ts +23 -0
- package/dist/adapter/vercel/handler.d.ts +10 -0
- package/dist/adapter/vercel.d.ts +13 -3
- package/dist/adapter/vercel.js +516 -0
- package/dist/build/bun-build.d.ts +4 -0
- package/dist/build/compile-entry.ts +1 -0
- package/dist/build/discover-mounts-process.d.ts +1 -0
- package/dist/build/discover-mounts.d.ts +6 -0
- package/dist/build/elysia-aot-worker.d.ts +4 -0
- package/dist/build/elysia-aot.d.ts +7 -1
- package/dist/build/entry-template.d.ts +14 -7
- package/dist/build/entry-template.ts +33 -18
- package/dist/build/hydrate.d.ts +15 -2
- package/dist/build/index.d.ts +7 -3
- package/dist/build/index.js +8842 -15395
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/route-types.d.ts +8 -2
- package/dist/build/server-app-entry.d.ts +2 -2
- package/dist/build/shared.d.ts +3 -5
- package/dist/build/types.d.ts +16 -16
- package/dist/cache.js +117 -32
- package/dist/cli/config.d.ts +2 -2
- package/dist/cli/index.js +8953 -15269
- package/dist/client/chunks/client-brdfd773.js +852 -0
- package/dist/client/chunks/client-k29262a4.js +59 -0
- package/dist/client/chunks/client-k88668k7.js +159 -0
- package/dist/client/chunks/client-xy6g38kx.js +317 -0
- package/dist/client/default-screens.d.ts +0 -11
- package/dist/client/define-route.d.ts +2 -1
- package/dist/client/hmr.d.ts +1 -1
- package/dist/client/internal/runtime-types.d.ts +7 -1
- package/dist/client/link.d.ts +1 -0
- package/dist/client/link.js +1790 -4190
- package/dist/client/mutation.d.ts +5 -0
- package/dist/client/query-store.d.ts +17 -7
- package/dist/client/query.d.ts +6 -8
- package/dist/client/request-id.d.ts +1 -0
- package/dist/client/route-api.d.ts +4 -4
- package/dist/client/route-element.d.ts +51 -0
- package/dist/client/router/boundary-tree.d.ts +1 -9
- package/dist/client/router/cache-generation.d.ts +15 -0
- package/dist/client/router/context.d.ts +13 -2
- package/dist/client/router/fetch-observers.d.ts +9 -0
- package/dist/client/router/hmr-refresh.d.ts +12 -0
- package/dist/client/router/index.d.ts +5 -7
- package/dist/client/router/link-utils.d.ts +0 -2
- package/dist/client/router/navigation-controller.d.ts +76 -0
- package/dist/client/router/navigation.d.ts +1 -0
- package/dist/client/router/page-fetch.d.ts +38 -0
- package/dist/client/router/provider.d.ts +2 -3
- package/dist/client/router/search/index.d.ts +11 -4
- package/dist/client/router/search/index.js +60 -0
- package/dist/client/router/spa-response.d.ts +9 -26
- package/dist/client/router/sync-catch-up.d.ts +3 -2
- package/dist/client/router/transport.d.ts +4 -0
- package/dist/client/router/types.d.ts +120 -46
- package/dist/client/router/use-fetch-interception.d.ts +12 -0
- package/dist/client/router/use-history-sync.d.ts +7 -0
- package/dist/client/router/use-hmr-refresh.d.ts +8 -0
- package/dist/client/router/use-sync-stream.d.ts +16 -0
- package/dist/client/server-error.d.ts +4 -7
- package/dist/client/sync.d.ts +43 -30
- package/dist/client.d.ts +2 -1
- package/dist/client.js +279 -829
- package/dist/config.d.ts +11 -12
- package/dist/config.js +0 -30
- package/dist/define-route.d.ts +262 -517
- package/dist/devtools/protocol.d.ts +4 -3
- package/dist/furin.d.ts +41 -31
- package/dist/furin.js +20560 -18970
- package/dist/plugin/binding-scope.d.ts +15 -2
- package/dist/plugin/client-plugin.d.ts +19 -0
- package/dist/plugin/dead-code-elimination.d.ts +14 -3
- package/dist/plugin/dev-routes.d.ts +22 -0
- package/dist/plugin/hmr-data-signature.d.ts +3 -0
- package/dist/plugin/hmr-hook-signature.d.ts +9 -0
- package/dist/plugin/index.d.ts +1 -6
- package/dist/plugin/index.js +1753 -1214
- package/dist/plugin/module-bindings.d.ts +11 -0
- package/dist/plugin/module-transform.d.ts +29 -0
- package/dist/plugin/preflight.d.ts +8 -0
- package/dist/plugin/route-chains.d.ts +35 -0
- package/dist/plugin/route-config.d.ts +28 -0
- package/dist/plugin/route-modules.d.ts +35 -0
- package/dist/plugin/route-registry.d.ts +12 -0
- package/dist/plugin/route-tree.d.ts +43 -0
- package/dist/plugin/strip-server-stages.d.ts +10 -0
- package/dist/plugin/strip-server.d.ts +10 -0
- package/dist/plugin/transform-client-module.d.ts +3 -0
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +3 -2
- package/dist/routes.d.ts +15 -5
- package/dist/rsc/build/client-references.d.ts +8 -0
- package/dist/rsc/build/discover.d.ts +7 -0
- package/dist/rsc/build/flight-loader.d.ts +1 -0
- package/dist/rsc/build/index.d.ts +4 -1
- package/dist/rsc/build/paths.d.ts +2 -0
- package/dist/rsc/bundled-client-codec.d.ts +1 -0
- package/dist/rsc/client-codec.d.ts +3 -0
- package/dist/rsc/client-references.d.ts +22 -0
- package/dist/rsc/server-client-codec.d.ts +1 -0
- package/dist/rsc/server-codec.js +3889 -2
- package/dist/rsc/slot-proxy.d.ts +11 -0
- package/dist/rsc/transport-benchmark.d.ts +2 -1
- package/dist/rsc-client.js +16 -164
- package/dist/rsc-server.d.ts +1 -5
- package/dist/rsc.d.ts +1 -5
- package/dist/rsc.js +233 -73
- package/dist/server/assets/client-dir.d.ts +1 -0
- package/dist/server/auto-invalidate/index.d.ts +2 -2
- package/dist/server/auto-invalidate/plugin.d.ts +21 -15
- package/dist/server/auto-invalidate/types.d.ts +0 -2
- package/dist/server/bounded-body.d.ts +6 -0
- package/dist/server/browser-events/plugin.d.ts +4 -1
- package/dist/server/browser-events/shutdown.d.ts +1 -1
- package/dist/server/cache/dev-loader.d.ts +6 -1
- package/dist/server/cache/index.d.ts +4 -9
- package/dist/server/cache/invalidation.d.ts +7 -2
- package/dist/server/cache/isr-ssg.d.ts +6 -1
- package/dist/server/cache/page-cache.d.ts +5 -0
- package/dist/server/cache/purger.d.ts +14 -4
- package/dist/server/cache/redis/index.d.ts +1 -34
- package/dist/server/cache/redis/index.js +51 -25
- package/dist/server/cache/redis/scripts.d.ts +1 -1
- package/dist/server/cache/route-cache.d.ts +18 -2
- package/dist/server/cache/runtime-cache.d.ts +7 -0
- package/dist/server/context-logger.d.ts +6 -1
- package/dist/server/dev/graph.d.ts +4 -3
- package/dist/server/dev/runtime.d.ts +4 -0
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev/stack-location.d.ts +9 -0
- package/dist/server/dev-page-imports.d.ts +42 -0
- package/dist/server/dev-page-plugin.d.ts +2 -49
- package/dist/server/devtools/instrumentation.d.ts +1 -3
- package/dist/server/devtools/instrumentation.production.d.ts +0 -2
- package/dist/server/devtools/request-context.d.ts +7 -0
- package/dist/server/evlog.d.ts +18 -6
- package/dist/server/instance.d.ts +52 -44
- package/dist/server/internal.d.ts +51 -14
- package/dist/server/internal.js +9749 -2095
- package/dist/server/lang-detect.d.ts +4 -4
- package/dist/server/logger.d.ts +6 -0
- package/dist/server/logging/ingest-plugin.d.ts +32 -0
- package/dist/server/mode.d.ts +17 -0
- package/dist/server/prerender.d.ts +32 -0
- package/dist/server/prod/runtime.d.ts +5 -0
- package/dist/server/production-server.js +992 -726
- package/dist/server/registrations.d.ts +14 -0
- package/dist/server/render/assemble.d.ts +0 -22
- package/dist/server/render/buffered-render.d.ts +20 -0
- package/dist/server/render/document-stream.d.ts +45 -0
- package/dist/server/render/document.d.ts +1 -1
- package/dist/server/render/element.d.ts +2 -5
- package/dist/server/render/index.d.ts +4 -5
- package/dist/server/render/index.ts +4 -21
- package/dist/server/render/isr-revalidation.d.ts +5 -0
- package/dist/server/render/isr-shared-cache.d.ts +23 -0
- package/dist/server/render/isr.d.ts +19 -1
- package/dist/server/render/loader-errors.d.ts +33 -0
- package/dist/server/render/loader-segments.d.ts +40 -0
- package/dist/server/render/loaders.d.ts +16 -32
- package/dist/server/render/mixed-cache.d.ts +2 -2
- package/dist/server/render/navigation-head.d.ts +13 -0
- package/dist/server/render/not-found-plugin.d.ts +18 -0
- package/dist/server/render/observe-loader.d.ts +1 -0
- package/dist/server/render/ppr-document.d.ts +1 -1
- package/dist/server/render/ppr-request.d.ts +0 -2
- package/dist/server/render/ppr-route.d.ts +13 -2
- package/dist/server/render/prepare-render.d.ts +57 -0
- package/dist/server/render/request-loaders.d.ts +19 -0
- package/dist/server/render/route-frame-transport.d.ts +7 -1
- package/dist/server/render/shell.d.ts +1 -1
- package/dist/server/render/shell.ts +1 -1
- package/dist/server/render/ssr-transport.d.ts +11 -0
- package/dist/server/render/ssr.d.ts +1 -116
- package/dist/server/render/static-params.d.ts +15 -0
- package/dist/server/router/discovery.d.ts +1 -0
- package/dist/server/router/dispatch.d.ts +96 -0
- package/dist/server/router/hmr.d.ts +14 -24
- package/dist/server/router/patterns.d.ts +15 -20
- package/dist/server/router/plugin.d.ts +26 -24
- package/dist/server/router/schemas.d.ts +6 -24
- package/dist/server/router/types.d.ts +0 -2
- package/dist/server/runtime-env.d.ts +6 -1
- package/dist/server/static-export.d.ts +38 -0
- package/dist/server/static-export.js +10667 -0
- package/dist/server/sync/adapter.d.ts +11 -0
- package/dist/server/sync/atomic.d.ts +0 -2
- package/dist/server/sync/config.d.ts +0 -1
- package/dist/server/sync/drizzle/index.js +112 -68
- package/dist/server/sync/fingerprint.d.ts +0 -1
- package/dist/server/sync/index.d.ts +2 -6
- package/dist/server/sync/index.js +1689 -1364
- package/dist/server/sync/invalidate-sync.d.ts +10 -0
- package/dist/server/sync/plugin.d.ts +18 -55
- package/dist/server/sync/postgres/execute.d.ts +2 -2
- package/dist/server/sync/postgres/index.d.ts +3 -1
- package/dist/server/sync/postgres/index.js +68 -37
- package/dist/server/sync/postgres/migration.sql +2 -0
- package/dist/server/sync/principal-journal.d.ts +11 -0
- package/dist/server/sync/prisma/index.js +74 -39
- package/dist/server/sync/queries.d.ts +57 -16
- package/dist/server/sync/redis/index.d.ts +2 -1
- package/dist/server/sync/redis/index.js +49 -5
- package/dist/server/sync/redis/scripts.d.ts +2 -1
- package/dist/server/sync/response.d.ts +3 -0
- package/dist/server/sync/runtime.d.ts +5 -1
- package/dist/server/sync/sqlite/index.d.ts +3 -1
- package/dist/server/sync/sqlite/index.js +58 -27
- package/dist/server/sync/stream.d.ts +32 -7
- package/dist/server/weak-registry.d.ts +9 -0
- package/dist/shared/await.d.ts +2 -1
- package/dist/shared/compact-json.d.ts +1 -0
- package/dist/shared/defer.d.ts +1 -1
- package/dist/shared/deferred-ndjson.d.ts +3 -2
- package/dist/shared/elysia-contract.d.ts +2 -0
- package/dist/shared/in-memory-apps.d.ts +7 -0
- package/dist/shared/invalidation-header.d.ts +13 -0
- package/dist/shared/navigation-data.d.ts +7 -0
- package/dist/shared/prefix.d.ts +11 -5
- package/dist/shared/route-frame.d.ts +3 -0
- package/dist/shared/route-map.d.ts +7 -0
- package/dist/shared/route-matches.d.ts +41 -0
- package/dist/shared/route-specificity.d.ts +2 -0
- package/dist/shared/search-params.d.ts +2 -3
- package/dist/shared/sync-query.d.ts +6 -13
- package/dist/shared/utils/ast-walk.d.ts +3 -11
- package/package.json +32 -21
- package/src/adapter/README.md +37 -16
- package/src/adapter/build.ts +269 -0
- package/src/adapter/bun/server.ts +14 -0
- package/src/adapter/bun.ts +89 -265
- package/src/adapter/furin-app.d.ts +14 -0
- package/src/adapter/package.ts +31 -27
- package/src/adapter/prerender.ts +97 -0
- package/src/adapter/runtime-build.ts +83 -93
- package/src/adapter/server-bundle.ts +110 -0
- package/src/adapter/static.ts +259 -247
- package/src/adapter/types.ts +89 -0
- package/src/adapter/vercel/bootstrap.ts +85 -0
- package/src/adapter/vercel/data.ts +21 -0
- package/src/adapter/vercel/handler.ts +132 -0
- package/src/adapter/vercel.ts +329 -659
- package/src/build/bun-build.ts +3 -0
- package/src/build/client.ts +22 -60
- package/src/build/compile-entry.ts +1 -0
- package/src/build/discover-mounts-process.ts +13 -0
- package/src/build/discover-mounts.ts +40 -0
- package/src/build/elysia-aot-worker.ts +84 -2
- package/src/build/elysia-aot.ts +61 -2
- package/src/build/entry-template.ts +33 -18
- package/src/build/hydrate.ts +122 -44
- package/src/build/index.ts +156 -108
- package/src/build/private-server-sourcemaps.ts +5 -0
- package/src/build/production-instrumentation.ts +22 -19
- package/src/build/route-types.ts +93 -11
- package/src/build/server-app-entry.ts +4 -21
- package/src/build/shared.ts +9 -41
- package/src/build/types.ts +14 -20
- package/src/build/virtual-entry.ts +2 -4
- package/src/cli/config.ts +133 -6
- package/src/cli/index.ts +59 -21
- package/src/cli/preview.ts +2 -1
- package/src/client/boundaries.tsx +5 -14
- package/src/client/default-screens.tsx +2 -2
- package/src/client/define-route.ts +3 -2
- package/src/client/hmr.ts +1 -1
- package/src/client/internal/runtime-types.ts +7 -1
- package/src/client/link.tsx +80 -43
- package/src/client/mutation.ts +98 -3
- package/src/client/query-store.ts +160 -29
- package/src/client/query.tsx +12 -29
- package/src/client/request-id.ts +10 -0
- package/src/client/route-api.tsx +6 -6
- package/src/client/route-element.tsx +155 -0
- package/src/client/router/boundary-tree.tsx +2 -93
- package/src/client/router/cache-generation.ts +37 -0
- package/src/client/router/context.ts +40 -4
- package/src/client/router/fetch-observers.ts +46 -0
- package/src/client/router/hmr-refresh.ts +50 -0
- package/src/client/router/index.ts +7 -29
- package/src/client/router/link-utils.ts +19 -31
- package/src/client/router/navigation-controller.ts +547 -0
- package/src/client/router/navigation.ts +3 -2
- package/src/client/router/optimistic.ts +2 -3
- package/src/client/router/page-fetch.ts +272 -0
- package/src/client/router/provider.tsx +223 -1079
- package/src/client/router/search/index.ts +38 -14
- package/src/client/router/spa-response.ts +19 -70
- package/src/client/router/sync-catch-up.ts +65 -7
- package/src/client/router/transport.ts +23 -0
- package/src/client/router/types.ts +203 -61
- package/src/client/router/use-fetch-interception.ts +52 -0
- package/src/client/router/use-history-sync.ts +56 -0
- package/src/client/router/use-hmr-refresh.ts +51 -0
- package/src/client/router/use-sync-stream.ts +129 -0
- package/src/client/server-error.ts +2 -40
- package/src/client/sync.ts +268 -378
- package/src/client.ts +2 -7
- package/src/config.ts +23 -45
- package/src/define-route.ts +487 -882
- package/src/devtools/devtools-element.js +10 -3
- package/src/devtools/protocol.ts +3 -3
- package/src/furin.ts +253 -1086
- package/src/plugin/binding-scope.ts +219 -94
- package/src/plugin/client-plugin.ts +145 -0
- package/src/plugin/dead-code-elimination.ts +390 -111
- package/src/plugin/dev-routes.ts +453 -0
- package/src/plugin/hmr-data-signature.ts +161 -0
- package/src/plugin/hmr-dependencies.ts +2 -4
- package/src/plugin/hmr-hook-signature.ts +252 -0
- package/src/plugin/index.ts +3 -96
- package/src/plugin/module-bindings.ts +216 -0
- package/src/plugin/module-transform.ts +63 -0
- package/src/plugin/preflight.ts +66 -0
- package/src/plugin/route-chains.ts +309 -0
- package/src/plugin/route-config.ts +451 -0
- package/src/plugin/route-modules.ts +209 -0
- package/src/plugin/route-registry.ts +316 -0
- package/src/plugin/route-tree.ts +248 -0
- package/src/plugin/strip-server-stages.ts +197 -0
- package/src/plugin/strip-server.ts +22 -0
- package/src/plugin/transform-client-module.ts +36 -31
- package/src/plugin/transform-client.ts +33 -1114
- package/src/plugin/transform-dev-page.ts +84 -92
- package/src/plugin/transform-isomorphic.ts +396 -185
- package/src/routes.ts +15 -5
- package/src/rsc/build/client-references.ts +267 -0
- package/src/rsc/build/discover.ts +226 -0
- package/src/rsc/build/flight-loader.ts +69 -0
- package/src/rsc/build/index.ts +53 -31
- package/src/rsc/build/paths.ts +7 -0
- package/src/rsc/bundled-client-codec.ts +4 -0
- package/src/rsc/client-codec.ts +12 -3
- package/src/rsc/client-references.ts +138 -0
- package/src/rsc/codec.ts +30 -21
- package/src/rsc/flight-drain.ts +6 -29
- package/src/rsc/react-server-dom-webpack.d.ts +1 -1
- package/src/rsc/server-client-codec.ts +14 -0
- package/src/rsc/server-codec.ts +5 -8
- package/src/rsc/slot-proxy.ts +34 -0
- package/src/rsc/transport-benchmark.ts +1 -1
- package/src/rsc-server.tsx +5 -23
- package/src/rsc.tsx +5 -29
- package/src/server/assets/client-dir.ts +110 -0
- package/src/server/assets/production.ts +1 -1
- package/src/server/auto-invalidate/index.ts +2 -7
- package/src/server/auto-invalidate/plugin.ts +43 -15
- package/src/server/auto-invalidate/registry.ts +6 -6
- package/src/server/auto-invalidate/runtime.ts +16 -98
- package/src/server/auto-invalidate/types.ts +0 -6
- package/src/server/bounded-body.ts +38 -0
- package/src/server/browser-events/plugin.ts +109 -22
- package/src/server/browser-events/shutdown.ts +28 -9
- package/src/server/cache/dev-loader.ts +30 -16
- package/src/server/cache/index.ts +2 -15
- package/src/server/cache/invalidation.ts +27 -46
- package/src/server/cache/isr-ssg.ts +6 -1
- package/src/server/cache/isr.ts +11 -11
- package/src/server/cache/page-cache-state.ts +2 -2
- package/src/server/cache/page-cache.ts +13 -9
- package/src/server/cache/purger.ts +64 -8
- package/src/server/cache/redis/index.ts +17 -27
- package/src/server/cache/redis/scripts.ts +21 -4
- package/src/server/cache/registry.ts +3 -3
- package/src/server/cache/route-cache.ts +47 -13
- package/src/server/cache/runtime-cache.ts +144 -24
- package/src/server/cache/ssg.ts +7 -5
- package/src/server/context-logger.ts +46 -8
- package/src/server/dev/diagnostics.ts +6 -56
- package/src/server/dev/error.ts +3 -34
- package/src/server/dev/graph.ts +35 -22
- package/src/server/dev/rewrite-module-specifiers.ts +15 -19
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev/runtime.ts +404 -0
- package/src/server/dev/stack-location.ts +46 -0
- package/src/server/dev-page-imports.ts +183 -0
- package/src/server/dev-page-plugin.ts +39 -302
- package/src/server/devtools/hub.ts +3 -3
- package/src/server/devtools/instrumentation.production.ts +0 -8
- package/src/server/devtools/instrumentation.ts +6 -8
- package/src/server/devtools/plugin.ts +2 -1
- package/src/server/devtools/request-context.ts +67 -16
- package/src/server/evlog.ts +119 -55
- package/src/server/instance.ts +187 -138
- package/src/server/internal.ts +66 -62
- package/src/server/lang-detect.ts +31 -22
- package/src/server/logger.ts +20 -7
- package/src/server/logging/ingest-plugin.ts +123 -0
- package/src/server/mode.ts +19 -0
- package/src/server/prerender.ts +122 -0
- package/src/server/prod/runtime.ts +181 -0
- package/src/server/production-server.ts +43 -17
- package/src/server/registrations.ts +38 -0
- package/src/server/render/assemble.ts +5 -8
- package/src/server/render/buffered-render.ts +171 -0
- package/src/server/render/document-stream.ts +188 -0
- package/src/server/render/document.tsx +5 -3
- package/src/server/render/element.tsx +6 -73
- package/src/server/render/index.ts +4 -21
- package/src/server/render/isr-revalidation.ts +246 -0
- package/src/server/render/isr-shared-cache.ts +141 -0
- package/src/server/render/isr.ts +212 -516
- package/src/server/render/loader-errors.ts +183 -0
- package/src/server/render/loader-segments.ts +149 -0
- package/src/server/render/loaders.ts +126 -547
- package/src/server/render/mixed-cache.ts +28 -27
- package/src/server/render/navigation-head.ts +33 -0
- package/src/server/render/not-found-plugin.ts +31 -0
- package/src/server/render/not-found.ts +32 -8
- package/src/server/render/observe-loader.ts +46 -0
- package/src/server/render/ppr-document.ts +36 -14
- package/src/server/render/ppr-request.ts +2 -2
- package/src/server/render/ppr-route.ts +79 -18
- package/src/server/render/prepare-render.ts +251 -0
- package/src/server/render/request-loaders.ts +216 -0
- package/src/server/render/route-frame-transport.ts +41 -4
- package/src/server/render/shell.ts +1 -1
- package/src/server/render/ssg.ts +9 -20
- package/src/server/render/ssr-transport.ts +221 -0
- package/src/server/render/ssr.ts +95 -956
- package/src/server/render/static-params.ts +32 -0
- package/src/server/render/template.ts +7 -7
- package/src/server/router/discovery.ts +82 -159
- package/src/server/router/dispatch.ts +337 -0
- package/src/server/router/hmr.ts +177 -190
- package/src/server/router/patterns.ts +39 -65
- package/src/server/router/plugin.ts +234 -359
- package/src/server/router/schemas.ts +6 -39
- package/src/server/router/source-version.ts +5 -4
- package/src/server/router/types.ts +0 -2
- package/src/server/runtime-env.ts +6 -1
- package/src/server/static-export.ts +143 -0
- package/src/server/sync/adapter.ts +11 -0
- package/src/server/sync/atomic.ts +16 -36
- package/src/server/sync/config.ts +6 -14
- package/src/server/sync/drizzle/index.ts +12 -20
- package/src/server/sync/fingerprint.ts +1 -1
- package/src/server/sync/index.ts +2 -10
- package/src/server/sync/invalidate-sync.ts +31 -0
- package/src/server/sync/mutation-handler.ts +6 -0
- package/src/server/sync/plugin.ts +171 -129
- package/src/server/sync/postgres/execute.ts +9 -1
- package/src/server/sync/postgres/index.ts +71 -39
- package/src/server/sync/postgres/migration.sql +2 -0
- package/src/server/sync/principal-journal.ts +78 -0
- package/src/server/sync/prisma/index.ts +1 -0
- package/src/server/sync/queries.ts +133 -40
- package/src/server/sync/query-context.ts +38 -5
- package/src/server/sync/redis/index.ts +34 -6
- package/src/server/sync/redis/scripts.ts +10 -1
- package/src/server/sync/response.ts +47 -67
- package/src/server/sync/runtime.ts +24 -7
- package/src/server/sync/sqlite/index.ts +92 -61
- package/src/server/sync/sqlite/migration.sql +1 -0
- package/src/server/sync/stream.ts +47 -26
- package/src/server/sync/validation.ts +1 -1
- package/src/server/weak-registry.ts +37 -0
- package/src/shared/await.tsx +2 -1
- package/src/shared/compact-json.ts +1 -1
- package/src/shared/defer.ts +1 -1
- package/src/shared/deferred-ndjson.ts +142 -120
- package/src/shared/elysia-contract.ts +7 -0
- package/src/shared/error.ts +1 -4
- package/src/shared/in-memory-apps.ts +24 -0
- package/src/shared/invalidation-header.ts +38 -0
- package/src/shared/navigation-data.ts +29 -0
- package/src/shared/prefix.ts +42 -6
- package/src/shared/route-frame.ts +82 -26
- package/src/shared/route-map.ts +23 -39
- package/src/shared/route-matches.ts +59 -0
- package/src/shared/route-specificity.ts +28 -0
- package/src/shared/search-params.ts +6 -35
- package/src/shared/sync-query.ts +30 -23
- package/src/shared/utils/ast-walk.ts +9 -25
- package/src/shared/utils/index.ts +1 -1
- package/dist/build/scan-server.d.ts +0 -14
- package/dist/build/ssg-cache.d.ts +0 -18
- package/dist/plugin/route-config-autofix.d.ts +0 -31
- package/dist/plugin/routes.d.ts +0 -34
- package/dist/server/router/hmr.production.d.ts +0 -7
- package/src/build/scan-server.ts +0 -112
- package/src/build/ssg-cache.ts +0 -126
- package/src/plugin/route-config-autofix.ts +0 -1149
- package/src/plugin/routes.ts +0 -1140
- package/src/server/router/hmr.production.ts +0 -18
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InvalidationRule } from "../auto-invalidate/types.ts";
|
|
2
|
+
import type { SyncRuntimeOptions } from "./adapter.ts";
|
|
3
|
+
import type { SyncParams, SyncPattern } from "./queries.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Invalidates outside a request (cron, webhook) what the handler's `invalidate()` takes — a GET
|
|
6
|
+
* pattern and its params, cache tags or a page path: purges the pages built from it, then
|
|
7
|
+
* journals and broadcasts it through the runtime `sync` configures, as a mutation would.
|
|
8
|
+
*/
|
|
9
|
+
export declare function invalidateSync<Target extends SyncPattern>(sync: SyncRuntimeOptions, pattern: Target, params?: NoInfer<SyncParams<Target>>): Promise<void>;
|
|
10
|
+
export declare function invalidateSync(sync: SyncRuntimeOptions, rule: InvalidationRule): Promise<void>;
|
|
@@ -1,77 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { InvalidationInput } from "../auto-invalidate/types.ts";
|
|
1
|
+
import { type Context, Elysia } from "elysia";
|
|
3
2
|
import type { SyncAdapter, SyncMutation, SyncRuntimeOptions } from "./adapter.ts";
|
|
4
3
|
import { MutationLeaseLost } from "./execution-error.ts";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/** `idempotent: false`: no Idempotency-Key, replay or `mutation()`; invalidations still apply. */
|
|
5
|
+
declare function idempotentRouteMacro(_idempotent: false): {
|
|
6
|
+
transform({ request }: Pick<Context, "request">): void;
|
|
8
7
|
};
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
8
|
+
/** Whether a `furinSync()` runtime owns the request's route. */
|
|
9
|
+
export declare function isSyncRequest(request: Request): boolean;
|
|
11
10
|
export declare function furinSync<Adapter extends SyncAdapter>(options: SyncRuntimeOptions<Adapter>): (app: Elysia) => Elysia<"", "local", {
|
|
12
11
|
decorator: {};
|
|
13
12
|
store: {};
|
|
14
13
|
derive: {
|
|
15
14
|
readonly mutation: SyncMutation<Adapter>;
|
|
15
|
+
readonly invalidate: import("./queries.ts").SyncInvalidate;
|
|
16
16
|
};
|
|
17
17
|
}, {
|
|
18
18
|
typebox: {};
|
|
19
|
-
error: [import("elysia/types").ErrorDefinitionEntry<typeof MutationLeaseLost, Promise<void
|
|
19
|
+
error: [import("elysia/types").ErrorDefinitionEntry<typeof MutationLeaseLost, Promise<void>>, {
|
|
20
|
+
error: Error;
|
|
21
|
+
response: {};
|
|
22
|
+
passes: true;
|
|
23
|
+
'~return': void;
|
|
24
|
+
'~catchAll': true;
|
|
25
|
+
}];
|
|
20
26
|
}, import("elysia").DefaultMetadata & {
|
|
21
27
|
schema: {};
|
|
22
28
|
schemas: {};
|
|
23
29
|
macro: Partial<{
|
|
24
|
-
readonly
|
|
30
|
+
readonly idempotent: false;
|
|
25
31
|
}>;
|
|
26
32
|
macroFn: {
|
|
27
|
-
readonly
|
|
28
|
-
transform({ request }: {
|
|
29
|
-
server: import("elysia").Server | null;
|
|
30
|
-
redirect: import("elysia").redirect;
|
|
31
|
-
set: {
|
|
32
|
-
headers: import("elysia").HTTPHeaders;
|
|
33
|
-
status?: number | keyof import("elysia").StatusMap;
|
|
34
|
-
cookie?: Record<string, import("elysia").BaseCookie>;
|
|
35
|
-
redirect?: never;
|
|
36
|
-
};
|
|
37
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = import("elysia").StatusResponse<Code>>(code: Code, response?: T) => ElysiaStatus<Code, T, import("elysia").NumericStatus<Code>>;
|
|
38
|
-
problem: typeof import("elysia").problem;
|
|
39
|
-
defer: (fn: import("elysia/types").AfterResponseHandler<import("elysia/types").IntersectIfObjectSchema<import("elysia/types").UnwrapMacroSchema<{
|
|
40
|
-
body: undefined;
|
|
41
|
-
headers: undefined;
|
|
42
|
-
query: undefined;
|
|
43
|
-
params: undefined;
|
|
44
|
-
cookie: undefined;
|
|
45
|
-
response: undefined;
|
|
46
|
-
}, {}>, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>, {
|
|
47
|
-
decorator: {};
|
|
48
|
-
store: {};
|
|
49
|
-
derive: {
|
|
50
|
-
readonly mutation: SyncMutation<Adapter>;
|
|
51
|
-
};
|
|
52
|
-
} & {
|
|
53
|
-
derive: Partial<{}>;
|
|
54
|
-
} & {
|
|
55
|
-
derive: {
|
|
56
|
-
readonly mutation: SyncMutation<Adapter>;
|
|
57
|
-
} & Partial<{}>;
|
|
58
|
-
}>) => import("elysia/types").MaybePromise<void>;
|
|
59
|
-
readonly path: string;
|
|
60
|
-
route?: string;
|
|
61
|
-
rid?: string;
|
|
62
|
-
request: Request;
|
|
63
|
-
store: {};
|
|
64
|
-
body: unknown;
|
|
65
|
-
query: Record<string, string | undefined>;
|
|
66
|
-
params: Record<string, string>;
|
|
67
|
-
headers: Record<string, string | undefined>;
|
|
68
|
-
cookie: Record<string, import("elysia").Cookie<unknown>>;
|
|
69
|
-
readonly mutation: SyncMutation<Adapter>;
|
|
70
|
-
}): void;
|
|
71
|
-
};
|
|
33
|
+
readonly idempotent: typeof idempotentRouteMacro;
|
|
72
34
|
};
|
|
73
35
|
parser: {};
|
|
74
|
-
response:
|
|
36
|
+
response: import("elysia/types").ExtractErrorFromHandle<void>;
|
|
75
37
|
}, {}, import("elysia").DefaultEphemeral, {
|
|
76
38
|
derive: {};
|
|
77
39
|
schema: {};
|
|
@@ -79,3 +41,4 @@ export declare function furinSync<Adapter extends SyncAdapter>(options: SyncRunt
|
|
|
79
41
|
response: {};
|
|
80
42
|
error: [];
|
|
81
43
|
}>;
|
|
44
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AtomicMutationResult, AtomicMutationValue, MutationLease } from "../adapter.ts";
|
|
1
|
+
import type { AtomicMutationResult, AtomicMutationValue, MutationLease, SyncAdapter } from "../adapter.ts";
|
|
2
2
|
import type { PostgresSyncAdapter } from "./index.ts";
|
|
3
|
-
export declare function executePostgresMutation<T, Tx>(journal: PostgresSyncAdapter, lease: MutationLease, tx: Tx, callback: (tx: Tx) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>): Promise<AtomicMutationResult<T>>;
|
|
3
|
+
export declare function executePostgresMutation<T, Tx>(owner: SyncAdapter, journal: PostgresSyncAdapter, lease: MutationLease, tx: Tx, callback: (tx: Tx) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>): Promise<AtomicMutationResult<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SQL } from "bun";
|
|
2
|
-
import type { BeginMutationInput, BeginMutationResult, ChangePage, CompleteMutationInput, CompleteMutationResult, MutationLease, ReadChangesInput, SyncAdapter, SyncNotifier, SyncSubscription } from "../adapter.ts";
|
|
2
|
+
import type { BeginMutationInput, BeginMutationResult, ChangePage, CompleteMutationInput, CompleteMutationResult, MutationLease, ReadChangesInput, SyncAdapter, SyncInvalidation, SyncNotifier, SyncSubscription } from "../adapter.ts";
|
|
3
3
|
import type { SyncSql } from "./sql.ts";
|
|
4
4
|
export interface PostgresSyncAdapterOptions {
|
|
5
5
|
namespace: string;
|
|
@@ -22,6 +22,8 @@ export declare class PostgresSyncAdapter implements SyncAdapter {
|
|
|
22
22
|
/** Only used on the native transaction that already holds lockMutation's row lock. */
|
|
23
23
|
completeLockedMutation(input: CompleteMutationInput): Promise<CompleteMutationResult>;
|
|
24
24
|
private completeMutationInTransaction;
|
|
25
|
+
appendInvalidations(invalidations: readonly SyncInvalidation[]): Promise<string>;
|
|
26
|
+
private appendChangeInTransaction;
|
|
25
27
|
lockMutation(lease: MutationLease): Promise<boolean>;
|
|
26
28
|
private lockMutationInTransaction;
|
|
27
29
|
abortMutation(lease: MutationLease): Promise<void>;
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/server/sync/principal-journal.ts
|
|
3
|
+
var principalJournals = new WeakSet;
|
|
4
|
+
var changePrincipals = new WeakMap;
|
|
5
|
+
var principalSecrets = new WeakMap;
|
|
6
|
+
function principalHash(adapter, principal) {
|
|
7
|
+
const secret = principalSecrets.get(adapter);
|
|
8
|
+
const hasher = secret === undefined ? new Bun.CryptoHasher("sha256") : new Bun.CryptoHasher("sha256", secret);
|
|
9
|
+
return hasher.update(principal).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
function registerPrincipalJournal(adapter) {
|
|
12
|
+
principalJournals.add(adapter);
|
|
13
|
+
}
|
|
14
|
+
function journalChange(change, hash) {
|
|
15
|
+
if (hash !== undefined && hash !== null) {
|
|
16
|
+
changePrincipals.set(change, hash);
|
|
17
|
+
}
|
|
18
|
+
return change;
|
|
19
|
+
}
|
|
20
|
+
|
|
2
21
|
// src/server/sync/postgres/index.ts
|
|
3
22
|
var CHANGE_RETENTION = 1000;
|
|
4
23
|
var LEASE_MS = 30000;
|
|
@@ -45,6 +64,7 @@ class PostgresSyncAdapter {
|
|
|
45
64
|
this.publishesNotifications = options.publishNotifications !== false;
|
|
46
65
|
this.namespace = options.namespace;
|
|
47
66
|
this.sql = options.sql;
|
|
67
|
+
registerPrincipalJournal(this);
|
|
48
68
|
}
|
|
49
69
|
beginMutation(input) {
|
|
50
70
|
return this.sql.begin(async (tx) => {
|
|
@@ -145,40 +165,7 @@ class PostgresSyncAdapter {
|
|
|
145
165
|
if (!await this.lockMutationInTransaction(tx, input.lease, checkExpiration)) {
|
|
146
166
|
return { kind: "lost" };
|
|
147
167
|
}
|
|
148
|
-
|
|
149
|
-
if (input.invalidations.length > 0) {
|
|
150
|
-
await tx`
|
|
151
|
-
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
152
|
-
VALUES (${this.namespace}, 0, 0)
|
|
153
|
-
ON CONFLICT (namespace) DO NOTHING
|
|
154
|
-
`;
|
|
155
|
-
const cursors = await tx`
|
|
156
|
-
UPDATE furin_sync.streams
|
|
157
|
-
SET current_cursor = current_cursor + 1
|
|
158
|
-
WHERE namespace = ${this.namespace}
|
|
159
|
-
RETURNING current_cursor
|
|
160
|
-
`;
|
|
161
|
-
cursor = String(cursors[0]?.current_cursor);
|
|
162
|
-
await tx`
|
|
163
|
-
INSERT INTO furin_sync.changes (namespace, cursor, invalidations)
|
|
164
|
-
VALUES (
|
|
165
|
-
${this.namespace},
|
|
166
|
-
${cursor},
|
|
167
|
-
${JSON.stringify(input.invalidations)}::text::jsonb
|
|
168
|
-
)
|
|
169
|
-
`;
|
|
170
|
-
await tx`
|
|
171
|
-
WITH removed AS (
|
|
172
|
-
DELETE FROM furin_sync.changes
|
|
173
|
-
WHERE namespace = ${this.namespace}
|
|
174
|
-
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
175
|
-
RETURNING cursor
|
|
176
|
-
)
|
|
177
|
-
UPDATE furin_sync.streams
|
|
178
|
-
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
179
|
-
WHERE namespace = ${this.namespace}
|
|
180
|
-
`;
|
|
181
|
-
}
|
|
168
|
+
const cursor = input.invalidations.length > 0 ? await this.appendChangeInTransaction(tx, input.invalidations, principalHash(this, input.lease.principal)) : undefined;
|
|
182
169
|
await tx`
|
|
183
170
|
UPDATE furin_sync.mutations
|
|
184
171
|
SET state = 'succeeded',
|
|
@@ -197,6 +184,50 @@ class PostgresSyncAdapter {
|
|
|
197
184
|
return { cursor, kind: "committed" };
|
|
198
185
|
});
|
|
199
186
|
}
|
|
187
|
+
appendInvalidations(invalidations) {
|
|
188
|
+
return this.sql.begin(async (tx) => {
|
|
189
|
+
const cursor = await this.appendChangeInTransaction(tx, invalidations, null);
|
|
190
|
+
if (this.publishesNotifications) {
|
|
191
|
+
await tx.notify(this.notificationChannel, cursor);
|
|
192
|
+
}
|
|
193
|
+
return cursor;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async appendChangeInTransaction(tx, invalidations, principal) {
|
|
197
|
+
await tx`
|
|
198
|
+
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
199
|
+
VALUES (${this.namespace}, 0, 0)
|
|
200
|
+
ON CONFLICT (namespace) DO NOTHING
|
|
201
|
+
`;
|
|
202
|
+
const cursors = await tx`
|
|
203
|
+
UPDATE furin_sync.streams
|
|
204
|
+
SET current_cursor = current_cursor + 1
|
|
205
|
+
WHERE namespace = ${this.namespace}
|
|
206
|
+
RETURNING current_cursor
|
|
207
|
+
`;
|
|
208
|
+
const cursor = String(cursors[0]?.current_cursor);
|
|
209
|
+
await tx`
|
|
210
|
+
INSERT INTO furin_sync.changes (namespace, cursor, invalidations, principal_hash)
|
|
211
|
+
VALUES (
|
|
212
|
+
${this.namespace},
|
|
213
|
+
${cursor},
|
|
214
|
+
${JSON.stringify(invalidations)}::text::jsonb,
|
|
215
|
+
${principal}
|
|
216
|
+
)
|
|
217
|
+
`;
|
|
218
|
+
await tx`
|
|
219
|
+
WITH removed AS (
|
|
220
|
+
DELETE FROM furin_sync.changes
|
|
221
|
+
WHERE namespace = ${this.namespace}
|
|
222
|
+
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
223
|
+
RETURNING cursor
|
|
224
|
+
)
|
|
225
|
+
UPDATE furin_sync.streams
|
|
226
|
+
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
227
|
+
WHERE namespace = ${this.namespace}
|
|
228
|
+
`;
|
|
229
|
+
return cursor;
|
|
230
|
+
}
|
|
200
231
|
lockMutation(lease) {
|
|
201
232
|
return this.sql.begin((tx) => this.lockMutationInTransaction(tx, lease, true));
|
|
202
233
|
}
|
|
@@ -246,7 +277,7 @@ class PostgresSyncAdapter {
|
|
|
246
277
|
return { changes: [], cursor: currentCursor, hasMore: false, reset: true };
|
|
247
278
|
}
|
|
248
279
|
const rows = await this.sql`
|
|
249
|
-
SELECT cursor, invalidations
|
|
280
|
+
SELECT cursor, invalidations, principal_hash
|
|
250
281
|
FROM furin_sync.changes
|
|
251
282
|
WHERE namespace = ${this.namespace} AND cursor > ${input.after}::bigint
|
|
252
283
|
ORDER BY cursor ASC
|
|
@@ -267,10 +298,10 @@ class PostgresSyncAdapter {
|
|
|
267
298
|
};
|
|
268
299
|
}
|
|
269
300
|
const hasMore = rows.length > input.limit;
|
|
270
|
-
const changes = rows.slice(0, input.limit).map((row) => ({
|
|
301
|
+
const changes = rows.slice(0, input.limit).map((row) => journalChange({
|
|
271
302
|
cursor: String(row.cursor),
|
|
272
303
|
invalidations: row.invalidations
|
|
273
|
-
}));
|
|
304
|
+
}, row.principal_hash));
|
|
274
305
|
return {
|
|
275
306
|
changes,
|
|
276
307
|
cursor: changes.at(-1)?.cursor ?? input.after,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChangePage, ReadChangesInput, SyncAdapter, SyncChange } from "./adapter.ts";
|
|
2
|
+
/** Binds the runtime's `secret` to its adapter so every principal hash uses one key. */
|
|
3
|
+
export declare function configurePrincipalSecret(adapter: SyncAdapter, secret: string | undefined, development: boolean): void;
|
|
4
|
+
/** Transaction-scoped journals hash principals with the secret of the adapter that owns them. */
|
|
5
|
+
export declare function sharePrincipalSecret(journal: SyncAdapter, owner: SyncAdapter): void;
|
|
6
|
+
/** HMAC-SHA256 with the adapter's configured secret, or SHA-256 without one. */
|
|
7
|
+
export declare function principalHash(adapter: SyncAdapter, principal: string): string;
|
|
8
|
+
/** Built-in journals record provenance; arbitrary adapter output is never trusted. */
|
|
9
|
+
export declare function registerPrincipalJournal(adapter: SyncAdapter): void;
|
|
10
|
+
export declare function journalChange(change: SyncChange, hash: string | null | undefined): SyncChange;
|
|
11
|
+
export declare function readPrincipalChanges(adapter: SyncAdapter, input: ReadChangesInput, principal: string): Promise<ChangePage>;
|
|
@@ -3,8 +3,31 @@
|
|
|
3
3
|
class MutationLeaseLost extends Error {
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// src/server/sync/principal-journal.ts
|
|
7
|
+
var principalJournals = new WeakSet;
|
|
8
|
+
var changePrincipals = new WeakMap;
|
|
9
|
+
var principalSecrets = new WeakMap;
|
|
10
|
+
function sharePrincipalSecret(journal, owner) {
|
|
11
|
+
principalSecrets.set(journal, principalSecrets.get(owner));
|
|
12
|
+
}
|
|
13
|
+
function principalHash(adapter, principal) {
|
|
14
|
+
const secret = principalSecrets.get(adapter);
|
|
15
|
+
const hasher = secret === undefined ? new Bun.CryptoHasher("sha256") : new Bun.CryptoHasher("sha256", secret);
|
|
16
|
+
return hasher.update(principal).digest("hex");
|
|
17
|
+
}
|
|
18
|
+
function registerPrincipalJournal(adapter) {
|
|
19
|
+
principalJournals.add(adapter);
|
|
20
|
+
}
|
|
21
|
+
function journalChange(change, hash) {
|
|
22
|
+
if (hash !== undefined && hash !== null) {
|
|
23
|
+
changePrincipals.set(change, hash);
|
|
24
|
+
}
|
|
25
|
+
return change;
|
|
26
|
+
}
|
|
27
|
+
|
|
6
28
|
// src/server/sync/postgres/execute.ts
|
|
7
|
-
async function executePostgresMutation(journal, lease, tx, callback) {
|
|
29
|
+
async function executePostgresMutation(owner, journal, lease, tx, callback) {
|
|
30
|
+
sharePrincipalSecret(journal, owner);
|
|
8
31
|
if (!await journal.lockMutation(lease)) {
|
|
9
32
|
throw new MutationLeaseLost("[furin] Mutation lease lost; the transaction was rolled back.");
|
|
10
33
|
}
|
|
@@ -59,6 +82,7 @@ class PostgresSyncAdapter {
|
|
|
59
82
|
this.publishesNotifications = options.publishNotifications !== false;
|
|
60
83
|
this.namespace = options.namespace;
|
|
61
84
|
this.sql = options.sql;
|
|
85
|
+
registerPrincipalJournal(this);
|
|
62
86
|
}
|
|
63
87
|
beginMutation(input) {
|
|
64
88
|
return this.sql.begin(async (tx) => {
|
|
@@ -159,40 +183,7 @@ class PostgresSyncAdapter {
|
|
|
159
183
|
if (!await this.lockMutationInTransaction(tx, input.lease, checkExpiration)) {
|
|
160
184
|
return { kind: "lost" };
|
|
161
185
|
}
|
|
162
|
-
|
|
163
|
-
if (input.invalidations.length > 0) {
|
|
164
|
-
await tx`
|
|
165
|
-
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
166
|
-
VALUES (${this.namespace}, 0, 0)
|
|
167
|
-
ON CONFLICT (namespace) DO NOTHING
|
|
168
|
-
`;
|
|
169
|
-
const cursors = await tx`
|
|
170
|
-
UPDATE furin_sync.streams
|
|
171
|
-
SET current_cursor = current_cursor + 1
|
|
172
|
-
WHERE namespace = ${this.namespace}
|
|
173
|
-
RETURNING current_cursor
|
|
174
|
-
`;
|
|
175
|
-
cursor = String(cursors[0]?.current_cursor);
|
|
176
|
-
await tx`
|
|
177
|
-
INSERT INTO furin_sync.changes (namespace, cursor, invalidations)
|
|
178
|
-
VALUES (
|
|
179
|
-
${this.namespace},
|
|
180
|
-
${cursor},
|
|
181
|
-
${JSON.stringify(input.invalidations)}::text::jsonb
|
|
182
|
-
)
|
|
183
|
-
`;
|
|
184
|
-
await tx`
|
|
185
|
-
WITH removed AS (
|
|
186
|
-
DELETE FROM furin_sync.changes
|
|
187
|
-
WHERE namespace = ${this.namespace}
|
|
188
|
-
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
189
|
-
RETURNING cursor
|
|
190
|
-
)
|
|
191
|
-
UPDATE furin_sync.streams
|
|
192
|
-
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
193
|
-
WHERE namespace = ${this.namespace}
|
|
194
|
-
`;
|
|
195
|
-
}
|
|
186
|
+
const cursor = input.invalidations.length > 0 ? await this.appendChangeInTransaction(tx, input.invalidations, principalHash(this, input.lease.principal)) : undefined;
|
|
196
187
|
await tx`
|
|
197
188
|
UPDATE furin_sync.mutations
|
|
198
189
|
SET state = 'succeeded',
|
|
@@ -211,6 +202,50 @@ class PostgresSyncAdapter {
|
|
|
211
202
|
return { cursor, kind: "committed" };
|
|
212
203
|
});
|
|
213
204
|
}
|
|
205
|
+
appendInvalidations(invalidations) {
|
|
206
|
+
return this.sql.begin(async (tx) => {
|
|
207
|
+
const cursor = await this.appendChangeInTransaction(tx, invalidations, null);
|
|
208
|
+
if (this.publishesNotifications) {
|
|
209
|
+
await tx.notify(this.notificationChannel, cursor);
|
|
210
|
+
}
|
|
211
|
+
return cursor;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async appendChangeInTransaction(tx, invalidations, principal) {
|
|
215
|
+
await tx`
|
|
216
|
+
INSERT INTO furin_sync.streams (namespace, current_cursor, oldest_cursor)
|
|
217
|
+
VALUES (${this.namespace}, 0, 0)
|
|
218
|
+
ON CONFLICT (namespace) DO NOTHING
|
|
219
|
+
`;
|
|
220
|
+
const cursors = await tx`
|
|
221
|
+
UPDATE furin_sync.streams
|
|
222
|
+
SET current_cursor = current_cursor + 1
|
|
223
|
+
WHERE namespace = ${this.namespace}
|
|
224
|
+
RETURNING current_cursor
|
|
225
|
+
`;
|
|
226
|
+
const cursor = String(cursors[0]?.current_cursor);
|
|
227
|
+
await tx`
|
|
228
|
+
INSERT INTO furin_sync.changes (namespace, cursor, invalidations, principal_hash)
|
|
229
|
+
VALUES (
|
|
230
|
+
${this.namespace},
|
|
231
|
+
${cursor},
|
|
232
|
+
${JSON.stringify(invalidations)}::text::jsonb,
|
|
233
|
+
${principal}
|
|
234
|
+
)
|
|
235
|
+
`;
|
|
236
|
+
await tx`
|
|
237
|
+
WITH removed AS (
|
|
238
|
+
DELETE FROM furin_sync.changes
|
|
239
|
+
WHERE namespace = ${this.namespace}
|
|
240
|
+
AND cursor <= GREATEST(0, ${cursor}::bigint - ${CHANGE_RETENTION})
|
|
241
|
+
RETURNING cursor
|
|
242
|
+
)
|
|
243
|
+
UPDATE furin_sync.streams
|
|
244
|
+
SET oldest_cursor = COALESCE((SELECT MAX(cursor) + 1 FROM removed), oldest_cursor)
|
|
245
|
+
WHERE namespace = ${this.namespace}
|
|
246
|
+
`;
|
|
247
|
+
return cursor;
|
|
248
|
+
}
|
|
214
249
|
lockMutation(lease) {
|
|
215
250
|
return this.sql.begin((tx) => this.lockMutationInTransaction(tx, lease, true));
|
|
216
251
|
}
|
|
@@ -260,7 +295,7 @@ class PostgresSyncAdapter {
|
|
|
260
295
|
return { changes: [], cursor: currentCursor, hasMore: false, reset: true };
|
|
261
296
|
}
|
|
262
297
|
const rows = await this.sql`
|
|
263
|
-
SELECT cursor, invalidations
|
|
298
|
+
SELECT cursor, invalidations, principal_hash
|
|
264
299
|
FROM furin_sync.changes
|
|
265
300
|
WHERE namespace = ${this.namespace} AND cursor > ${input.after}::bigint
|
|
266
301
|
ORDER BY cursor ASC
|
|
@@ -281,10 +316,10 @@ class PostgresSyncAdapter {
|
|
|
281
316
|
};
|
|
282
317
|
}
|
|
283
318
|
const hasMore = rows.length > input.limit;
|
|
284
|
-
const changes = rows.slice(0, input.limit).map((row) => ({
|
|
319
|
+
const changes = rows.slice(0, input.limit).map((row) => journalChange({
|
|
285
320
|
cursor: String(row.cursor),
|
|
286
321
|
invalidations: row.invalidations
|
|
287
|
-
}));
|
|
322
|
+
}, row.principal_hash));
|
|
288
323
|
return {
|
|
289
324
|
changes,
|
|
290
325
|
cursor: changes.at(-1)?.cursor ?? input.after,
|
|
@@ -324,7 +359,7 @@ class PrismaSyncAdapter extends PostgresSyncAdapter {
|
|
|
324
359
|
this.syncNamespace = options.namespace;
|
|
325
360
|
}
|
|
326
361
|
executeMutation(lease, callback) {
|
|
327
|
-
return this.client.$transaction((tx) => executePostgresMutation(new PostgresSyncAdapter({
|
|
362
|
+
return this.client.$transaction((tx) => executePostgresMutation(this, new PostgresSyncAdapter({
|
|
328
363
|
namespace: this.syncNamespace,
|
|
329
364
|
sql: prismaSql(tx),
|
|
330
365
|
publishNotifications: false
|
|
@@ -1,21 +1,62 @@
|
|
|
1
|
+
import type { Register } from "@teyik0/furin/routes";
|
|
1
2
|
import type { Context } from "elysia";
|
|
2
|
-
import { type
|
|
3
|
-
import type { InvalidationInput,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { type QueryIdentity } from "../../shared/sync-query.ts";
|
|
4
|
+
import type { InvalidationInput, InvalidationRule } from "../auto-invalidate/types.ts";
|
|
5
|
+
/** A method's schema in an Eden route tree; path segments never carry these fields. */
|
|
6
|
+
interface RouteSchema {
|
|
7
|
+
body: unknown;
|
|
8
|
+
headers: unknown;
|
|
9
|
+
params: unknown;
|
|
10
|
+
query: unknown;
|
|
11
|
+
response: unknown;
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/** The GET route patterns of an Eden route tree, eg. `"/boards" | "/boards/:boardId"`. */
|
|
14
|
+
export type GetPatterns<Routes, Path extends string> = {
|
|
15
|
+
[Segment in keyof Routes & string]: Segment extends "get" ? Path extends "" ? "/" : Path : Routes[Segment] extends RouteSchema ? never : GetPatterns<Routes[Segment], `${Path}/${Segment}`>;
|
|
16
|
+
}[keyof Routes & string];
|
|
17
|
+
type ParamName<Param extends string> = Param extends `${infer Name}?` ? Name : Param;
|
|
18
|
+
type ParamNames<Pattern extends string> = Pattern extends `${string}:${infer Param}/${infer Rest}` ? ParamName<Param> | ParamNames<Rest> : Pattern extends `${string}:${infer Param}` ? ParamName<Param> : never;
|
|
19
|
+
/** The registered application's GET patterns; any path until one is registered. */
|
|
20
|
+
export type SyncPattern = Register extends {
|
|
21
|
+
app: {
|
|
22
|
+
"~Routes": infer Routes;
|
|
23
|
+
};
|
|
24
|
+
} ? GetPatterns<Routes, ""> : string;
|
|
25
|
+
/** A pattern's params; an omitted param matches every value. */
|
|
26
|
+
export type SyncParams<Pattern extends string> = string extends Pattern ? {
|
|
27
|
+
readonly [param: string]: string | number;
|
|
28
|
+
} : [ParamNames<Pattern>] extends [never] ? {
|
|
29
|
+
readonly [param: string]: never;
|
|
15
30
|
} : {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export type
|
|
19
|
-
|
|
31
|
+
readonly [Name in ParamNames<Pattern>]?: string | number;
|
|
32
|
+
};
|
|
33
|
+
export type Invalidate<Pattern extends string> = <Target extends Pattern>(pattern: Target, params?: NoInfer<SyncParams<Target>>) => void;
|
|
34
|
+
/**
|
|
35
|
+
* The handler's `invalidate()`: a GET pattern and its params, cache tags or a page path.
|
|
36
|
+
* An interface, unlike `Invalidate<SyncPattern>`, resolves `Register["app"]` lazily: the
|
|
37
|
+
* registered app's own handlers can call it without circularity.
|
|
38
|
+
*/
|
|
39
|
+
export interface SyncInvalidate {
|
|
40
|
+
<Target extends SyncPattern>(pattern: Target, params?: NoInfer<SyncParams<Target>>): void;
|
|
41
|
+
(rule: InvalidationRule): void;
|
|
42
|
+
}
|
|
43
|
+
export declare function isMutationMethod(method: string): boolean;
|
|
44
|
+
/** Furin's own sync endpoints are no live queries: their GETs carry no URL identity. */
|
|
45
|
+
export declare function markInternalRead(request: Request): void;
|
|
46
|
+
export declare function isInternalRead(request: Request): boolean;
|
|
47
|
+
/** `mutation()` resolved: its transaction already journaled the request's invalidations. */
|
|
48
|
+
export declare function sealInvalidations(request: Request): void;
|
|
49
|
+
/** The request's `invalidate()`: its targets only apply once the mutation succeeds or commits. */
|
|
50
|
+
export declare function requestInvalidate(request: Request): SyncInvalidate;
|
|
51
|
+
/** The URL identity of the request's own route: its registered pattern and params. */
|
|
52
|
+
export declare function urlIdentity(context: {
|
|
53
|
+
params?: {
|
|
54
|
+
readonly [name: string]: string | number | undefined;
|
|
55
|
+
};
|
|
56
|
+
path: string;
|
|
57
|
+
route?: string;
|
|
58
|
+
}): QueryIdentity;
|
|
59
|
+
/** The handler's `invalidate()` calls, then the GET at the mutation's own URL. */
|
|
60
|
+
export declare function resolveSyncInvalidations(context: Parameters<typeof urlIdentity>[0] & Pick<Context, "request">): InvalidationRule[];
|
|
20
61
|
export declare function appendQueryInvalidations(input: InvalidationInput | undefined, context: Pick<Context, "set">): void;
|
|
21
62
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RedisClient } from "bun";
|
|
2
|
-
import type { BeginMutationInput, BeginMutationResult, ChangePage, CompleteMutationInput, CompleteMutationResult, MutationLease, ReadChangesInput, SyncAdapter, SyncNotifier, SyncSubscription } from "../adapter.ts";
|
|
2
|
+
import type { BeginMutationInput, BeginMutationResult, ChangePage, CompleteMutationInput, CompleteMutationResult, MutationLease, ReadChangesInput, SyncAdapter, SyncInvalidation, SyncNotifier, SyncSubscription } from "../adapter.ts";
|
|
3
3
|
export interface RedisSyncOptions {
|
|
4
4
|
client: RedisClient;
|
|
5
5
|
namespace: string;
|
|
@@ -12,6 +12,7 @@ export declare class RedisSyncAdapter implements SyncAdapter {
|
|
|
12
12
|
beginMutation(input: BeginMutationInput): Promise<BeginMutationResult>;
|
|
13
13
|
renewMutation(lease: MutationLease): Promise<"lost" | "renewed">;
|
|
14
14
|
completeMutation(input: CompleteMutationInput): Promise<CompleteMutationResult>;
|
|
15
|
+
appendInvalidations(invalidations: readonly SyncInvalidation[]): Promise<string>;
|
|
15
16
|
abortMutation(lease: MutationLease): Promise<void>;
|
|
16
17
|
currentCursor(): Promise<string>;
|
|
17
18
|
readChanges(input: ReadChangesInput): Promise<ChangePage>;
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/server/sync/principal-journal.ts
|
|
3
|
+
var principalJournals = new WeakSet;
|
|
4
|
+
var changePrincipals = new WeakMap;
|
|
5
|
+
var principalSecrets = new WeakMap;
|
|
6
|
+
function principalHash(adapter, principal) {
|
|
7
|
+
const secret = principalSecrets.get(adapter);
|
|
8
|
+
const hasher = secret === undefined ? new Bun.CryptoHasher("sha256") : new Bun.CryptoHasher("sha256", secret);
|
|
9
|
+
return hasher.update(principal).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
function registerPrincipalJournal(adapter) {
|
|
12
|
+
principalJournals.add(adapter);
|
|
13
|
+
}
|
|
14
|
+
function journalChange(change, hash) {
|
|
15
|
+
if (hash !== undefined && hash !== null) {
|
|
16
|
+
changePrincipals.set(change, hash);
|
|
17
|
+
}
|
|
18
|
+
return change;
|
|
19
|
+
}
|
|
20
|
+
|
|
2
21
|
// src/server/sync/redis/scripts.ts
|
|
3
22
|
var BEGIN_MUTATION_SCRIPT = `
|
|
4
23
|
local raw = redis.call('GET', KEYS[1])
|
|
@@ -57,7 +76,7 @@ if ARGV[3] ~= '[]' then
|
|
|
57
76
|
local oldest = redis.call('XRANGE', KEYS[2], '-', '+', 'COUNT', 1)
|
|
58
77
|
if oldest[1] then redis.call('SET', KEYS[3], oldest[1][1]) end
|
|
59
78
|
end
|
|
60
|
-
cursor = redis.call('XADD', KEYS[2], 'MAXLEN', '=', ARGV[5], '*', 'data', ARGV[3])
|
|
79
|
+
cursor = redis.call('XADD', KEYS[2], 'MAXLEN', '=', ARGV[5], '*', 'data', ARGV[3], 'principal', ARGV[6])
|
|
61
80
|
end
|
|
62
81
|
redis.call('SET', KEYS[1], cjson.encode(value), 'PX', ARGV[4])
|
|
63
82
|
return {'committed', cursor}
|
|
@@ -71,6 +90,14 @@ if value.state == 'in-progress' and value.id == ARGV[1] then
|
|
|
71
90
|
end
|
|
72
91
|
return 0
|
|
73
92
|
`;
|
|
93
|
+
var APPEND_INVALIDATIONS_SCRIPT = `
|
|
94
|
+
local length = redis.call('XLEN', KEYS[1])
|
|
95
|
+
if length >= tonumber(ARGV[2]) then
|
|
96
|
+
local oldest = redis.call('XRANGE', KEYS[1], '-', '+', 'COUNT', 1)
|
|
97
|
+
if oldest[1] then redis.call('SET', KEYS[2], oldest[1][1]) end
|
|
98
|
+
end
|
|
99
|
+
return redis.call('XADD', KEYS[1], 'MAXLEN', '=', ARGV[2], '*', 'data', ARGV[1])
|
|
100
|
+
`;
|
|
74
101
|
|
|
75
102
|
// src/server/sync/redis/index.ts
|
|
76
103
|
var CHANGE_RETENTION = 1000;
|
|
@@ -152,7 +179,12 @@ function streamEntries(value) {
|
|
|
152
179
|
if (fields[0] !== "data") {
|
|
153
180
|
throw new Error("[furin-sync-redis] Invalid stream fields.");
|
|
154
181
|
}
|
|
155
|
-
|
|
182
|
+
const principalIndex = fields.indexOf("principal");
|
|
183
|
+
return [
|
|
184
|
+
cursor,
|
|
185
|
+
stringResult(fields[1], "stream data"),
|
|
186
|
+
principalIndex < 0 ? undefined : stringResult(fields[principalIndex + 1], "stream principal")
|
|
187
|
+
];
|
|
156
188
|
});
|
|
157
189
|
}
|
|
158
190
|
|
|
@@ -164,6 +196,7 @@ class RedisSyncAdapter {
|
|
|
164
196
|
assertNamespace(options.namespace);
|
|
165
197
|
this.client = options.client;
|
|
166
198
|
this.prefix = `furin:sync:{${encodeURIComponent(options.namespace)}}`;
|
|
199
|
+
registerPrincipalJournal(this);
|
|
167
200
|
}
|
|
168
201
|
async beginMutation(input) {
|
|
169
202
|
const id = crypto.randomUUID();
|
|
@@ -220,7 +253,8 @@ class RedisSyncAdapter {
|
|
|
220
253
|
JSON.stringify(serializeResponse(input.response)),
|
|
221
254
|
JSON.stringify(input.invalidations),
|
|
222
255
|
String(MUTATION_TTL_MS),
|
|
223
|
-
String(CHANGE_RETENTION)
|
|
256
|
+
String(CHANGE_RETENTION),
|
|
257
|
+
principalHash(this, input.lease.principal)
|
|
224
258
|
]), "complete mutation");
|
|
225
259
|
const kind = stringResult(result[0], "complete mutation kind");
|
|
226
260
|
if (kind === "lost") {
|
|
@@ -232,6 +266,16 @@ class RedisSyncAdapter {
|
|
|
232
266
|
const cursor = stringResult(result[1], "complete mutation cursor");
|
|
233
267
|
return cursor.length === 0 ? { cursor: undefined, kind } : { cursor, kind };
|
|
234
268
|
}
|
|
269
|
+
async appendInvalidations(invalidations) {
|
|
270
|
+
return stringResult(await this.client.send("EVAL", [
|
|
271
|
+
APPEND_INVALIDATIONS_SCRIPT,
|
|
272
|
+
"2",
|
|
273
|
+
this.streamKey,
|
|
274
|
+
this.trimmedKey,
|
|
275
|
+
JSON.stringify(invalidations),
|
|
276
|
+
String(CHANGE_RETENTION)
|
|
277
|
+
]), "append invalidations cursor");
|
|
278
|
+
}
|
|
235
279
|
async abortMutation(lease) {
|
|
236
280
|
await this.client.send("EVAL", [ABORT_MUTATION_SCRIPT, "1", this.mutationKey(lease), lease.id]);
|
|
237
281
|
}
|
|
@@ -273,10 +317,10 @@ class RedisSyncAdapter {
|
|
|
273
317
|
};
|
|
274
318
|
}
|
|
275
319
|
const hasMore = entries.length > input.limit;
|
|
276
|
-
const changes = entries.slice(0, input.limit).map(([cursor, raw]) => ({
|
|
320
|
+
const changes = entries.slice(0, input.limit).map(([cursor, raw, hash]) => journalChange({
|
|
277
321
|
cursor,
|
|
278
322
|
invalidations: JSON.parse(raw)
|
|
279
|
-
}));
|
|
323
|
+
}, hash));
|
|
280
324
|
return {
|
|
281
325
|
changes,
|
|
282
326
|
cursor: changes.at(-1)?.cursor ?? input.after,
|