@teyik0/furin 0.2.0-alpha.4 → 0.3.0-alpha.1
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 +2 -3
- package/dist/adapter/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +88 -83
- package/dist/build/entry-template.d.ts +37 -9
- package/dist/build/entry-template.ts +109 -56
- package/dist/build/hydrate.d.ts +2 -2
- package/dist/build/index.js +6817 -4544
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +5 -11
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +37 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +6854 -4549
- package/dist/client/boundaries.d.ts +4 -4
- package/dist/client/internal/runtime-types.d.ts +30 -0
- package/dist/client/link.d.ts +2 -1
- package/dist/client/link.js +712 -338
- package/dist/client/router/boundary-tree.d.ts +1 -1
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +5 -1
- package/dist/client/router/sync-catch-up.d.ts +4 -4
- package/dist/client/router/types.d.ts +2 -2
- package/dist/client-only.d.ts +1 -0
- package/dist/client-only.js +1 -0
- package/dist/client.d.ts +108 -111
- package/dist/client.js +16 -17
- package/dist/config.d.ts +11 -2
- package/dist/config.js +7 -3
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +40 -21
- package/dist/furin.js +7198 -3518
- package/dist/isomorphic.d.ts +18 -0
- package/dist/plugin/binding-scope.d.ts +2 -0
- package/dist/plugin/dead-code-elimination.d.ts +3 -0
- package/dist/plugin/index.js +933 -423
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +9 -0
- package/dist/rsc/build/environment.d.ts +2 -0
- package/dist/rsc/build/index.d.ts +15 -0
- package/dist/rsc/client-codec.d.ts +1 -0
- package/dist/rsc/codec.d.ts +4 -0
- package/dist/rsc/flight-drain.d.ts +11 -0
- package/dist/rsc/render-error.d.ts +17 -0
- package/dist/rsc/server-codec.d.ts +2 -0
- package/dist/rsc/server-codec.js +24 -0
- package/dist/rsc/shared.d.ts +30 -0
- package/dist/rsc/symbols.d.ts +2 -0
- package/dist/rsc/transport-benchmark.d.ts +13 -0
- package/dist/rsc/version.d.ts +7 -0
- package/dist/rsc-client.d.ts +4 -0
- package/dist/rsc-client.js +166 -0
- package/dist/rsc-server.d.ts +11 -0
- package/dist/rsc.d.ts +11 -0
- package/dist/rsc.js +353 -0
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/index.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +20 -2
- package/dist/server/cache/isr-ssg.d.ts +5 -1
- package/dist/server/cache/isr.d.ts +15 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/route-cache.d.ts +10 -8
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/dev-page-plugin.d.ts +4 -0
- package/dist/server/devtools/hub.d.ts +11 -0
- package/dist/server/devtools/instrumentation.d.ts +22 -0
- package/dist/server/devtools/instrumentation.production.d.ts +44 -0
- package/dist/server/devtools/plugin.d.ts +3 -0
- package/dist/server/devtools/request-context.d.ts +6 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +18 -1
- package/dist/server/internal.js +74 -7
- package/dist/server/lang-detect.d.ts +1 -0
- package/dist/server/render/assemble.d.ts +4 -0
- package/dist/server/render/element.d.ts +1 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +6 -2
- package/dist/server/render/loaders.d.ts +8 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +8 -0
- package/dist/server/render/route-frame-transport.d.ts +2 -0
- package/dist/server/render/shell.ts +0 -1
- package/dist/server/render/ssr.d.ts +2 -3
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/router/discovery.d.ts +1 -1
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/index.d.ts +2 -1
- package/dist/server/router/index.js +23 -23
- package/dist/server/router/index.ts +1 -1
- package/dist/server/router/patterns.d.ts +1 -1
- package/dist/server/router/plugin.d.ts +4 -7
- package/dist/server/router/schema-merge.d.ts +3 -0
- package/dist/server/router/schemas.d.ts +12 -7
- package/dist/server/router/types.d.ts +1 -1
- package/dist/server/runtime-env.js +2 -2
- package/dist/server/sync/adapter.d.ts +45 -26
- package/dist/server/sync/config.d.ts +9 -2
- package/dist/server/sync/fingerprint.d.ts +2 -1
- package/dist/server/sync/index.d.ts +15 -4
- package/dist/server/sync/index.js +2868 -0
- package/dist/server/sync/notifier.d.ts +18 -0
- package/dist/server/sync/plugin.d.ts +53 -54
- package/dist/server/sync/postgres/index.d.ts +19 -0
- package/dist/server/sync/postgres/index.js +252 -0
- package/dist/server/sync/postgres/migrate.d.ts +2 -0
- package/dist/server/sync/postgres/migrate.js +16 -0
- package/dist/server/sync/postgres/migration.sql +66 -0
- package/dist/server/sync/redis/index.d.ts +30 -0
- package/dist/server/sync/redis/index.js +336 -0
- package/dist/server/sync/redis/scripts.d.ts +4 -0
- package/dist/server/sync/response.d.ts +10 -1
- package/dist/server/sync/runtime.d.ts +6 -0
- package/dist/server/sync/sqlite/index.d.ts +20 -0
- package/dist/server/sync/sqlite/index.js +250 -0
- package/dist/server/sync/stream.d.ts +12 -4
- package/dist/server-only.d.ts +1 -0
- package/dist/server-only.js +1 -0
- package/dist/shared/parser.d.ts +2 -0
- package/dist/shared/prefix.d.ts +15 -0
- package/dist/shared/route-frame.d.ts +49 -0
- package/dist/shared/utils/index.d.ts +1 -1
- package/package.json +59 -12
- package/src/adapter/bun.ts +175 -55
- package/src/adapter/package.ts +208 -0
- package/src/adapter/static.ts +94 -48
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +31 -27
- package/src/build/compile-entry.ts +88 -83
- package/src/build/entry-template.ts +109 -56
- package/src/build/hydrate.ts +37 -10
- package/src/build/index.ts +111 -28
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +7 -8
- package/src/build/scan-server.ts +26 -9
- package/src/build/server-routes-entry.ts +5 -11
- package/src/build/ssg-cache.ts +13 -4
- package/src/build/types.ts +38 -1
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +73 -24
- package/src/client/boundaries.tsx +42 -18
- package/src/client/default-screens.tsx +4 -4
- package/src/client/internal/runtime-types.ts +31 -0
- package/src/client/link.tsx +35 -37
- package/src/client/router/boundary-tree.tsx +2 -2
- package/src/client/router/context.ts +13 -9
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +66 -3
- package/src/client/router/navigation.ts +9 -15
- package/src/client/router/provider.tsx +74 -52
- package/src/client/router/search/index.ts +5 -7
- package/src/client/router/search-store.ts +5 -1
- package/src/client/router/spa-response.ts +3 -4
- package/src/client/router/sync-catch-up.ts +9 -8
- package/src/client/router/types.ts +2 -2
- package/src/client/sync.ts +3 -2
- package/src/client-only.ts +1 -0
- package/src/client.ts +221 -174
- package/src/config.ts +14 -1
- package/src/devtools/devtools-element.js +884 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +414 -171
- package/src/isomorphic.ts +66 -0
- package/src/plugin/binding-scope.ts +158 -0
- package/src/plugin/dead-code-elimination.ts +202 -0
- package/src/plugin/index.ts +14 -18
- package/src/plugin/transform-client.ts +237 -273
- package/src/plugin/transform-isomorphic.ts +464 -0
- package/src/rsc/build/environment.ts +30 -0
- package/src/rsc/build/index.ts +94 -0
- package/src/rsc/client-codec.ts +11 -0
- package/src/rsc/codec.ts +85 -0
- package/src/rsc/flight-drain.ts +68 -0
- package/src/rsc/react-server-dom-webpack.d.ts +23 -0
- package/src/rsc/render-error.ts +120 -0
- package/src/rsc/server-codec.ts +25 -0
- package/src/rsc/shared.tsx +113 -0
- package/src/rsc/symbols.ts +2 -0
- package/src/rsc/transport-benchmark.ts +73 -0
- package/src/rsc/version.ts +57 -0
- package/src/rsc-client.ts +12 -0
- package/src/rsc-server.tsx +91 -0
- package/src/rsc.tsx +75 -0
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +58 -7
- package/src/server/cache/dev-loader.ts +143 -44
- package/src/server/cache/index.ts +7 -3
- package/src/server/cache/invalidation.ts +100 -41
- package/src/server/cache/isr-ssg.ts +12 -3
- package/src/server/cache/isr.ts +95 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/route-cache.ts +49 -36
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/context-logger.ts +7 -7
- package/src/server/dev-page-plugin.ts +8 -6
- package/src/server/devtools/hub.ts +64 -0
- package/src/server/devtools/instrumentation.production.ts +80 -0
- package/src/server/devtools/instrumentation.ts +72 -0
- package/src/server/devtools/plugin.ts +267 -0
- package/src/server/devtools/request-context.ts +76 -0
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +102 -5
- package/src/server/lang-detect.ts +14 -10
- package/src/server/render/assemble.ts +73 -10
- package/src/server/render/element.tsx +11 -8
- package/src/server/render/index.ts +6 -2
- package/src/server/render/isr.ts +154 -110
- package/src/server/render/loaders.ts +259 -45
- package/src/server/render/not-found.ts +18 -17
- package/src/server/render/ppr-route.ts +146 -0
- package/src/server/render/route-frame-transport.ts +62 -0
- package/src/server/render/shell.ts +0 -1
- package/src/server/render/ssg.ts +6 -5
- package/src/server/render/ssr.ts +170 -70
- package/src/server/render/template.ts +59 -25
- package/src/server/router/discovery.ts +39 -22
- package/src/server/router/hmr.ts +15 -13
- package/src/server/router/index.ts +1 -1
- package/src/server/router/patterns.ts +16 -15
- package/src/server/router/plugin.ts +151 -158
- package/src/server/router/schema-merge.ts +52 -0
- package/src/server/router/schemas.ts +55 -73
- package/src/server/router/types.ts +1 -1
- package/src/server/sync/adapter.ts +44 -28
- package/src/server/sync/config.ts +22 -9
- package/src/server/sync/fingerprint.ts +8 -3
- package/src/server/sync/index.ts +37 -13
- package/src/server/sync/notifier.ts +109 -0
- package/src/server/sync/plugin.ts +184 -90
- package/src/server/sync/postgres/index.ts +301 -0
- package/src/server/sync/postgres/migrate.ts +15 -0
- package/src/server/sync/postgres/migration.sql +66 -0
- package/src/server/sync/redis/index.ts +342 -0
- package/src/server/sync/redis/scripts.ts +74 -0
- package/src/server/sync/response.ts +141 -16
- package/src/server/sync/runtime.ts +27 -0
- package/src/server/sync/sql.d.ts +4 -0
- package/src/server/sync/sqlite/index.ts +337 -0
- package/src/server/sync/sqlite/migration.sql +70 -0
- package/src/server/sync/stream.ts +136 -70
- package/src/server-only.ts +1 -0
- package/src/shared/await.tsx +4 -4
- package/src/shared/deferred-ndjson.ts +34 -6
- package/src/shared/digest.ts +2 -2
- package/src/shared/parser.ts +5 -0
- package/src/shared/prefix.ts +38 -0
- package/src/shared/route-frame.ts +429 -0
- package/src/shared/search-params.ts +7 -7
- package/src/shared/utils/index.ts +5 -3
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/sync/memory-adapter.d.ts +0 -17
- package/src/server/dev-inspector.ts +0 -60
- package/src/server/sync/memory-adapter.ts +0 -196
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry";
|
|
2
|
-
import { type Cache, createRouteCache } from "./route-cache";
|
|
2
|
+
import { type Cache, createRouteCache, pathWithoutSearch } from "./route-cache";
|
|
3
3
|
|
|
4
4
|
export interface ISRCacheEntry {
|
|
5
5
|
generatedAt: number;
|
|
@@ -24,18 +24,27 @@ export interface SsgCacheEntry {
|
|
|
24
24
|
/** Maximum number of pre-rendered HTML entries (per mode) before LRU eviction. */
|
|
25
25
|
const MAX_HTML_CACHE_SIZE = 1000;
|
|
26
26
|
|
|
27
|
+
interface HtmlRouteCacheOptions<Entry> {
|
|
28
|
+
onDelete?: (key: string, entry: Entry) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
/**
|
|
28
32
|
* Builds the LRU cache backing one render mode's pre-rendered HTML. ISR and SSG
|
|
29
33
|
* share the same eviction bound and the same `onDelete` hook — which keeps the
|
|
30
34
|
* auto-invalidate path registry in sync — and differ only in entry shape and
|
|
31
35
|
* the diagnostic `name`.
|
|
32
36
|
*/
|
|
33
|
-
export function createHtmlRouteCache<Entry>(
|
|
37
|
+
export function createHtmlRouteCache<Entry>(
|
|
38
|
+
mode: "isr" | "ssg",
|
|
39
|
+
options?: HtmlRouteCacheOptions<Entry>
|
|
40
|
+
): Cache<Entry> {
|
|
34
41
|
return createRouteCache<Entry>({
|
|
35
42
|
maxSize: MAX_HTML_CACHE_SIZE,
|
|
36
43
|
name: `render:${mode}-html`,
|
|
37
|
-
onDelete: (key) => {
|
|
44
|
+
onDelete: (key, entry) => {
|
|
38
45
|
autoInvalidateRegistry.unregisterPath(key);
|
|
46
|
+
options?.onDelete?.(key, entry);
|
|
39
47
|
},
|
|
48
|
+
pathFromKey: pathWithoutSearch,
|
|
40
49
|
});
|
|
41
50
|
}
|
package/src/server/cache/isr.ts
CHANGED
|
@@ -1,17 +1,107 @@
|
|
|
1
|
+
import { allStateBuckets, type FurinInstance, instanceSlot } from "../instance.ts";
|
|
1
2
|
import { createHtmlRouteCache, type ISRCacheEntry } from "./isr-ssg";
|
|
3
|
+
import { registerCacheInvalidator } from "./registry";
|
|
4
|
+
import type { Cache } from "./route-cache";
|
|
5
|
+
import { createStoreView, type StoreView } from "./store-view";
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
interface ISRCacheState {
|
|
8
|
+
cache: Cache<ISRCacheEntry>;
|
|
9
|
+
generations: Map<string, Set<ISRCacheGeneration>>;
|
|
10
|
+
pendingRevalidations: Map<string, Promise<void>>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ISRCacheGeneration {
|
|
14
|
+
valid: boolean;
|
|
15
|
+
}
|
|
4
16
|
|
|
5
|
-
|
|
17
|
+
// Per-instance ISR HTML cache — registered against the owning instance's
|
|
18
|
+
// invalidator map on first access.
|
|
19
|
+
const instanceIsrCache = instanceSlot<ISRCacheState>((instance) => {
|
|
20
|
+
const generations = new Map<string, Set<ISRCacheGeneration>>();
|
|
21
|
+
const pendingRevalidations = new Map<string, Promise<void>>();
|
|
22
|
+
const cache = createHtmlRouteCache<ISRCacheEntry>("isr", {
|
|
23
|
+
onDelete: (key) => {
|
|
24
|
+
const pending = generations.get(key);
|
|
25
|
+
if (pending === undefined) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (const generation of pending) {
|
|
29
|
+
generation.valid = false;
|
|
30
|
+
}
|
|
31
|
+
generations.delete(key);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
registerCacheInvalidator(cache, instance);
|
|
35
|
+
return { cache, generations, pendingRevalidations };
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export function isrRouteCache(instance?: FurinInstance): Cache<ISRCacheEntry> {
|
|
39
|
+
return instanceIsrCache(instance).cache;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Raw store view over the current instance's ISR cache. */
|
|
43
|
+
export const isrCache: StoreView<ISRCacheEntry> = createStoreView(
|
|
44
|
+
() => instanceIsrCache().cache.store
|
|
45
|
+
);
|
|
6
46
|
|
|
7
47
|
export function getISRCache(key: string): ISRCacheEntry | undefined {
|
|
8
|
-
return
|
|
48
|
+
return instanceIsrCache().cache.get(key);
|
|
9
49
|
}
|
|
10
50
|
|
|
11
51
|
export function deleteISRCache(key: string): boolean {
|
|
12
|
-
return
|
|
52
|
+
return instanceIsrCache().cache.delete(key);
|
|
13
53
|
}
|
|
14
54
|
|
|
15
55
|
export function setISRCache(key: string, entry: ISRCacheEntry): void {
|
|
16
|
-
|
|
56
|
+
instanceIsrCache().cache.set(key, entry);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function captureISRCacheGeneration(key: string): ISRCacheGeneration {
|
|
60
|
+
const state = instanceIsrCache();
|
|
61
|
+
const generation = { valid: true };
|
|
62
|
+
const pending = state.generations.get(key);
|
|
63
|
+
if (pending === undefined) {
|
|
64
|
+
state.generations.set(key, new Set([generation]));
|
|
65
|
+
} else {
|
|
66
|
+
pending.add(generation);
|
|
67
|
+
}
|
|
68
|
+
return generation;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function releaseISRCacheGeneration(key: string, generation: ISRCacheGeneration): void {
|
|
72
|
+
const { generations } = instanceIsrCache();
|
|
73
|
+
const pending = generations.get(key);
|
|
74
|
+
pending?.delete(generation);
|
|
75
|
+
if (pending?.size === 0) {
|
|
76
|
+
generations.delete(key);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function setISRCacheIfGenerationUnchanged(
|
|
81
|
+
key: string,
|
|
82
|
+
entry: ISRCacheEntry,
|
|
83
|
+
generation: ISRCacheGeneration
|
|
84
|
+
): boolean {
|
|
85
|
+
releaseISRCacheGeneration(key, generation);
|
|
86
|
+
if (!generation.valid) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
instanceIsrCache().cache.set(key, entry);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function pendingISRRevalidations(): Map<string, Promise<void>> {
|
|
94
|
+
return instanceIsrCache().pendingRevalidations;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function clearPendingISRRevalidations(instance?: FurinInstance): void {
|
|
98
|
+
instanceIsrCache(instance).pendingRevalidations.clear();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function waitForPendingISRRevalidations(): Promise<void> {
|
|
102
|
+
const pending = allStateBuckets().flatMap((instance) => [
|
|
103
|
+
...instanceIsrCache(instance).pendingRevalidations.values(),
|
|
104
|
+
]);
|
|
105
|
+
await Promise.allSettled(pending);
|
|
106
|
+
await Bun.sleep(1);
|
|
17
107
|
}
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
+
import { type FurinInstance, instanceSlot } from "../instance.ts";
|
|
1
2
|
import type { Cache } from "./route-cache";
|
|
2
3
|
|
|
3
4
|
export type CacheInvalidator = Pick<Cache<unknown>, "invalidatePath" | "name">;
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// One invalidator map per furin instance — each instance owns its SSG/ISR/dev
|
|
7
|
+
// caches, so `revalidatePath` never reaches into a sibling app's entries by
|
|
8
|
+
// accident (cross-instance invalidation is explicit, see invalidation.ts).
|
|
9
|
+
const instanceInvalidators = instanceSlot(() => new Map<string, CacheInvalidator>());
|
|
6
10
|
|
|
7
|
-
export function registerCacheInvalidator(
|
|
8
|
-
|
|
11
|
+
export function registerCacheInvalidator(
|
|
12
|
+
invalidator: CacheInvalidator,
|
|
13
|
+
instance?: FurinInstance
|
|
14
|
+
): () => void {
|
|
15
|
+
const invalidators = instanceInvalidators(instance);
|
|
16
|
+
const existing = invalidators.get(invalidator.name);
|
|
9
17
|
if (existing !== undefined && existing !== invalidator) {
|
|
10
18
|
throw new Error(
|
|
11
|
-
`Cache invalidator "${invalidator.name}" is already registered with a different
|
|
19
|
+
`Cache invalidator "${invalidator.name}" is already registered for this furin instance with a different invalidator object.`
|
|
12
20
|
);
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
return () => {
|
|
16
|
-
if (_cacheInvalidators.get(invalidator.name) === invalidator) {
|
|
17
|
-
_cacheInvalidators.delete(invalidator.name);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
_cacheInvalidators.set(invalidator.name, invalidator);
|
|
22
|
+
invalidators.set(invalidator.name, invalidator);
|
|
22
23
|
return () => {
|
|
23
|
-
if (
|
|
24
|
-
|
|
24
|
+
if (invalidators.get(invalidator.name) === invalidator) {
|
|
25
|
+
invalidators.delete(invalidator.name);
|
|
25
26
|
}
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export function getCacheInvalidators(): IterableIterator<CacheInvalidator> {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function clearCacheInvalidators(): void {
|
|
34
|
-
_cacheInvalidators.clear();
|
|
30
|
+
export function getCacheInvalidators(instance?: FurinInstance): IterableIterator<CacheInvalidator> {
|
|
31
|
+
return instanceInvalidators(instance).values();
|
|
35
32
|
}
|
|
@@ -6,15 +6,15 @@ export interface CacheInvalidationResult {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface Cache<Entry> {
|
|
9
|
-
clear()
|
|
10
|
-
delete(key: string)
|
|
11
|
-
entries()
|
|
12
|
-
get(key: string)
|
|
13
|
-
has(key: string)
|
|
14
|
-
invalidatePath(path: string, type: RevalidateType)
|
|
15
|
-
keys()
|
|
9
|
+
clear: () => void;
|
|
10
|
+
delete: (key: string) => boolean;
|
|
11
|
+
entries: () => IterableIterator<[string, Entry]>;
|
|
12
|
+
get: (key: string) => Entry | undefined;
|
|
13
|
+
has: (key: string) => boolean;
|
|
14
|
+
invalidatePath: (path: string, type: RevalidateType) => CacheInvalidationResult;
|
|
15
|
+
keys: () => IterableIterator<string>;
|
|
16
16
|
readonly name: string;
|
|
17
|
-
set(key: string, entry: Entry)
|
|
17
|
+
set: (key: string, entry: Entry) => void;
|
|
18
18
|
get size(): number;
|
|
19
19
|
readonly store: Map<string, Entry>;
|
|
20
20
|
}
|
|
@@ -31,6 +31,19 @@ function defaultPathFromKey(key: string): string {
|
|
|
31
31
|
return key;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
export function pathWithoutSearch(path: string): string {
|
|
35
|
+
const searchStart = path.indexOf("?");
|
|
36
|
+
if (searchStart === -1) {
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
return path.slice(0, searchStart);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function pathWithRequestSearch(path: string, requestUrl: string): string {
|
|
43
|
+
const { search } = new URL(requestUrl);
|
|
44
|
+
return `${pathWithoutSearch(path)}${search}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
function matchesPath(urlPath: string, path: string, type: RevalidateType): boolean {
|
|
35
48
|
if (type === "page") {
|
|
36
49
|
return urlPath === path;
|
|
@@ -64,10 +77,17 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
64
77
|
};
|
|
65
78
|
|
|
66
79
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
clear() {
|
|
81
|
+
for (const key of [...store.keys()]) {
|
|
82
|
+
deleteEntry(key);
|
|
83
|
+
}
|
|
84
|
+
store.clear();
|
|
85
|
+
},
|
|
86
|
+
delete(key) {
|
|
87
|
+
return deleteEntry(key);
|
|
88
|
+
},
|
|
89
|
+
entries() {
|
|
90
|
+
return store.entries();
|
|
71
91
|
},
|
|
72
92
|
get(key) {
|
|
73
93
|
const entry = store.get(key);
|
|
@@ -77,33 +97,9 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
77
97
|
}
|
|
78
98
|
return entry;
|
|
79
99
|
},
|
|
80
|
-
set(key, entry) {
|
|
81
|
-
const previous = store.get(key);
|
|
82
|
-
if (previous !== undefined) {
|
|
83
|
-
store.delete(key);
|
|
84
|
-
}
|
|
85
|
-
store.set(key, entry);
|
|
86
|
-
options.onSet?.(key, entry, previous);
|
|
87
|
-
evictOldest();
|
|
88
|
-
},
|
|
89
|
-
delete(key) {
|
|
90
|
-
return deleteEntry(key);
|
|
91
|
-
},
|
|
92
|
-
clear() {
|
|
93
|
-
for (const key of [...store.keys()]) {
|
|
94
|
-
deleteEntry(key);
|
|
95
|
-
}
|
|
96
|
-
store.clear();
|
|
97
|
-
},
|
|
98
100
|
has(key) {
|
|
99
101
|
return store.has(key);
|
|
100
102
|
},
|
|
101
|
-
entries() {
|
|
102
|
-
return store.entries();
|
|
103
|
-
},
|
|
104
|
-
keys() {
|
|
105
|
-
return store.keys();
|
|
106
|
-
},
|
|
107
103
|
invalidatePath(path, type) {
|
|
108
104
|
let deleted = false;
|
|
109
105
|
const purgedPaths: string[] = [];
|
|
@@ -120,5 +116,22 @@ export function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cach
|
|
|
120
116
|
|
|
121
117
|
return { deleted, purgedPaths: [...new Set(purgedPaths)] };
|
|
122
118
|
},
|
|
119
|
+
keys() {
|
|
120
|
+
return store.keys();
|
|
121
|
+
},
|
|
122
|
+
name: options.name,
|
|
123
|
+
set(key, entry) {
|
|
124
|
+
const previous = store.get(key);
|
|
125
|
+
if (previous !== undefined) {
|
|
126
|
+
store.delete(key);
|
|
127
|
+
}
|
|
128
|
+
store.set(key, entry);
|
|
129
|
+
options.onSet?.(key, entry, previous);
|
|
130
|
+
evictOldest();
|
|
131
|
+
},
|
|
132
|
+
get size() {
|
|
133
|
+
return store.size;
|
|
134
|
+
},
|
|
135
|
+
store,
|
|
123
136
|
};
|
|
124
137
|
}
|
package/src/server/cache/ssg.ts
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry";
|
|
2
|
+
import { type FurinInstance, instanceSlot } from "../instance.ts";
|
|
2
3
|
import { createHtmlRouteCache, type SsgCacheEntry } from "./isr-ssg";
|
|
4
|
+
import { registerCacheInvalidator } from "./registry";
|
|
5
|
+
import type { Cache } from "./route-cache";
|
|
6
|
+
import { createStoreView, type StoreView } from "./store-view";
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
// Per-instance SSG HTML cache — registered against the owning instance's
|
|
9
|
+
// invalidator map on first access.
|
|
10
|
+
const instanceSsgCache = instanceSlot((instance) => {
|
|
11
|
+
const cache = createHtmlRouteCache<SsgCacheEntry>("ssg");
|
|
12
|
+
registerCacheInvalidator(cache, instance);
|
|
13
|
+
return cache;
|
|
14
|
+
});
|
|
5
15
|
|
|
6
|
-
export
|
|
16
|
+
export function ssgRouteCache(instance?: FurinInstance): Cache<SsgCacheEntry> {
|
|
17
|
+
return instanceSsgCache(instance);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Raw store view over the current instance's SSG cache. */
|
|
21
|
+
export const ssgCache: StoreView<SsgCacheEntry> = createStoreView(() => instanceSsgCache().store);
|
|
7
22
|
|
|
8
23
|
export function getSSGCache(key: string): SsgCacheEntry | undefined {
|
|
9
|
-
return
|
|
24
|
+
return instanceSsgCache().get(key);
|
|
10
25
|
}
|
|
11
26
|
|
|
12
27
|
export function setSSGCache(key: string, entry: SsgCacheEntry): void {
|
|
13
|
-
|
|
28
|
+
instanceSsgCache().set(key, entry);
|
|
14
29
|
autoInvalidateRegistry.registerLoaderTags(key, entry.tags);
|
|
15
30
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Map-like facade over a lazily-resolved backing store. Keeps the historical
|
|
2
|
+
// `ssgCache` / `isrCache` module exports working now that the real Map lives
|
|
3
|
+
// on the current furin instance (see server/instance.ts).
|
|
4
|
+
export interface StoreView<Entry> {
|
|
5
|
+
clear: () => void;
|
|
6
|
+
delete: (key: string) => boolean;
|
|
7
|
+
entries: () => IterableIterator<[string, Entry]>;
|
|
8
|
+
get: (key: string) => Entry | undefined;
|
|
9
|
+
has: (key: string) => boolean;
|
|
10
|
+
keys: () => IterableIterator<string>;
|
|
11
|
+
set: (key: string, entry: Entry) => void;
|
|
12
|
+
readonly size: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createStoreView<Entry>(resolve: () => Map<string, Entry>): StoreView<Entry> {
|
|
16
|
+
return {
|
|
17
|
+
clear: () => resolve().clear(),
|
|
18
|
+
delete: (key) => resolve().delete(key),
|
|
19
|
+
entries: () => resolve().entries(),
|
|
20
|
+
get: (key) => resolve().get(key),
|
|
21
|
+
has: (key) => resolve().has(key),
|
|
22
|
+
keys: () => resolve().keys(),
|
|
23
|
+
set: (key, entry) => {
|
|
24
|
+
resolve().set(key, entry);
|
|
25
|
+
},
|
|
26
|
+
get size() {
|
|
27
|
+
return resolve().size;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -11,19 +11,19 @@ export { createLogger };
|
|
|
11
11
|
* (not in a live request, not in a synthetic render scope).
|
|
12
12
|
*/
|
|
13
13
|
const noopLogger: RequestLogger = {
|
|
14
|
-
|
|
15
|
-
set: () => {},
|
|
16
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
17
|
-
setLevel: () => {},
|
|
14
|
+
emit: () => null,
|
|
18
15
|
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
19
16
|
error: () => {},
|
|
17
|
+
fork: (_label, fn) => fn() as undefined,
|
|
18
|
+
getContext: () => ({}),
|
|
20
19
|
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
21
20
|
info: () => {},
|
|
22
21
|
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
22
|
+
set: () => {},
|
|
23
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
24
|
+
setLevel: () => {},
|
|
25
|
+
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional no-op
|
|
23
26
|
warn: () => {},
|
|
24
|
-
emit: () => null,
|
|
25
|
-
getContext: () => ({}),
|
|
26
|
-
fork: (_label, fn) => fn() as undefined,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const syntheticRenderStorage = new AsyncLocalStorage<RequestLogger>();
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
|
|
54
54
|
import { dirname, resolve } from "node:path";
|
|
55
55
|
import { fileURLToPath } from "node:url";
|
|
56
|
+
import { transformIsomorphicFunctions } from "../plugin/transform-isomorphic.ts";
|
|
56
57
|
import { invalidateDevLoaderCacheBySource } from "./cache/dev-loader.ts";
|
|
57
58
|
|
|
58
59
|
// Matches ?furin-server with an optional &t=<ms> cache-buster.
|
|
@@ -314,7 +315,7 @@ function shouldSkipWorkspaceTransform(filePath: string): boolean {
|
|
|
314
315
|
return normalized.includes("/.furin/");
|
|
315
316
|
}
|
|
316
317
|
|
|
317
|
-
function transformDevSource(
|
|
318
|
+
export function transformDevSource(
|
|
318
319
|
raw: string,
|
|
319
320
|
filePath: string,
|
|
320
321
|
options: { rewriteBareImports: boolean; rewriteRelativeImports: boolean }
|
|
@@ -325,15 +326,16 @@ function transformDevSource(
|
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
const dir = dirname(filePath);
|
|
329
|
+
const serverSource = transformIsomorphicFunctions(raw, filePath, "server").code;
|
|
328
330
|
const sourceForTranspile = options.rewriteRelativeImports
|
|
329
|
-
? rewriteRelativeImports(
|
|
330
|
-
:
|
|
331
|
+
? rewriteRelativeImports(serverSource, dir)
|
|
332
|
+
: serverSource;
|
|
331
333
|
const transpiler = new Bun.Transpiler({ loader });
|
|
332
334
|
const transpiled = transpiler.transformSync(sourceForTranspile, loader);
|
|
333
335
|
|
|
334
336
|
let result = transpiled;
|
|
335
337
|
if (options.rewriteBareImports) {
|
|
336
|
-
result = rewriteBareImports(
|
|
338
|
+
result = rewriteBareImports(serverSource, result, dir);
|
|
337
339
|
}
|
|
338
340
|
|
|
339
341
|
result = rewriteSingletonImports(result);
|
|
@@ -356,7 +358,7 @@ export function registerDevPagePlugin(): void {
|
|
|
356
358
|
const tMatch = T_PARAM_RE.exec(args.path);
|
|
357
359
|
const filePath = args.path.replace(STRIP_FURIN_SERVER_RE, "");
|
|
358
360
|
const resolvedPath = tMatch ? `${filePath}?t=${tMatch[1]}` : filePath;
|
|
359
|
-
return {
|
|
361
|
+
return { namespace: "furin-dev-page", path: resolvedPath };
|
|
360
362
|
});
|
|
361
363
|
|
|
362
364
|
/**
|
|
@@ -436,7 +438,7 @@ export function registerDevPagePlugin(): void {
|
|
|
436
438
|
* • `injectJsxHelperImports` → adds the JSX helper imports that
|
|
437
439
|
* `Bun.Transpiler` emits as free variables without corresponding imports.
|
|
438
440
|
*/
|
|
439
|
-
build.onLoad({ namespace: "furin-dev-page"
|
|
441
|
+
build.onLoad({ filter: ANY_FILTER, namespace: "furin-dev-page" }, async (args) => {
|
|
440
442
|
const filePath = args.path.replace(STRIP_T_PARAM_RE, "");
|
|
441
443
|
const raw = await Bun.file(filePath).text();
|
|
442
444
|
const contents = transformDevSource(raw, filePath, {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEVTOOLS_PROTOCOL_VERSION,
|
|
3
|
+
type DevtoolsServerEvent,
|
|
4
|
+
type DevtoolsServerEventInput,
|
|
5
|
+
} from "../../devtools/protocol.ts";
|
|
6
|
+
import { currentInstance, instanceSlot } from "../instance.ts";
|
|
7
|
+
|
|
8
|
+
const EVENT_LIMIT = 1000;
|
|
9
|
+
|
|
10
|
+
interface DevtoolsHub {
|
|
11
|
+
events: DevtoolsServerEvent[];
|
|
12
|
+
listeners: Set<(event: DevtoolsServerEvent) => void>;
|
|
13
|
+
sequence: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const instanceDevtoolsHub = instanceSlot(
|
|
17
|
+
(): DevtoolsHub => ({ events: [], listeners: new Set(), sequence: 0 })
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export function devtoolsInstanceId(): string {
|
|
21
|
+
const instance = currentInstance();
|
|
22
|
+
return Bun.hash(`${instance.prefix}\0${instance.pagesDir}`).toString(16);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function devtoolsEventsSnapshot(): {
|
|
26
|
+
events: DevtoolsServerEvent[];
|
|
27
|
+
lastEventId: number;
|
|
28
|
+
} {
|
|
29
|
+
const hub = instanceDevtoolsHub();
|
|
30
|
+
return { events: [...hub.events], lastEventId: hub.sequence };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function subscribeDevtoolsEventsAfter(
|
|
34
|
+
cursor: number,
|
|
35
|
+
listener: (event: DevtoolsServerEvent) => void
|
|
36
|
+
): { replay: DevtoolsServerEvent[]; unsubscribe: () => void } {
|
|
37
|
+
const hub = instanceDevtoolsHub();
|
|
38
|
+
hub.listeners.add(listener);
|
|
39
|
+
return {
|
|
40
|
+
replay: hub.events.filter((event) => event.id > cursor),
|
|
41
|
+
unsubscribe: () => {
|
|
42
|
+
hub.listeners.delete(listener);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function appendDevtoolsEvent(event: DevtoolsServerEventInput): DevtoolsServerEvent {
|
|
48
|
+
const hub = instanceDevtoolsHub();
|
|
49
|
+
hub.sequence += 1;
|
|
50
|
+
const complete = {
|
|
51
|
+
...event,
|
|
52
|
+
id: hub.sequence,
|
|
53
|
+
instanceId: devtoolsInstanceId(),
|
|
54
|
+
version: DEVTOOLS_PROTOCOL_VERSION,
|
|
55
|
+
} as DevtoolsServerEvent;
|
|
56
|
+
hub.events.push(complete);
|
|
57
|
+
if (hub.events.length > EVENT_LIMIT) {
|
|
58
|
+
hub.events.shift();
|
|
59
|
+
}
|
|
60
|
+
for (const listener of hub.listeners) {
|
|
61
|
+
listener(complete);
|
|
62
|
+
}
|
|
63
|
+
return complete;
|
|
64
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type AnyElysia, Elysia } from "elysia";
|
|
2
|
+
import type { ResolvedRoute } from "../router/types.ts";
|
|
3
|
+
|
|
4
|
+
interface CacheAccessInput {
|
|
5
|
+
cache: "isr-loader" | "ssg-loader";
|
|
6
|
+
operationId: string | null;
|
|
7
|
+
outcome: "hit" | "miss" | "stale";
|
|
8
|
+
path: string;
|
|
9
|
+
requestId: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CacheInvalidatedInput {
|
|
13
|
+
deleted: boolean;
|
|
14
|
+
operationId: string | null;
|
|
15
|
+
purgedPaths: number;
|
|
16
|
+
reason: "path" | "source" | "tag";
|
|
17
|
+
requestId: string | null;
|
|
18
|
+
target: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface LoaderFinishedInput {
|
|
22
|
+
durationMs: number;
|
|
23
|
+
fieldNames: string[];
|
|
24
|
+
loader: string;
|
|
25
|
+
operationId: string | null;
|
|
26
|
+
path: string;
|
|
27
|
+
requestId: string;
|
|
28
|
+
status: "fulfilled" | "rejected";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface PayloadSerializedInput {
|
|
32
|
+
bytes: number;
|
|
33
|
+
kind: "route-data" | "rsc";
|
|
34
|
+
operationId: string | null;
|
|
35
|
+
path: string;
|
|
36
|
+
requestId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function emitCacheAccess(_event: CacheAccessInput): void {
|
|
40
|
+
// Production instrumentation is intentionally empty.
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function emitCacheInvalidated(_event: CacheInvalidatedInput): void {
|
|
44
|
+
// Production instrumentation is intentionally empty.
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function emitLoaderFinished(_event: LoaderFinishedInput): void {
|
|
48
|
+
// Production instrumentation is intentionally empty.
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function emitPayloadSerialized(_event: PayloadSerializedInput): void {
|
|
52
|
+
// Production instrumentation is intentionally empty.
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function currentInstrumentationRequest(): void {
|
|
56
|
+
// Production instrumentation has no request-local state.
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function runWithRequestInstrumentation<T>(_request: Request, fn: () => T): T {
|
|
60
|
+
return fn();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function shouldInstrumentRequest(_pathname: string, _prefix: string): boolean {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function instrumentationLoggerExclusions(_prefix: string): string[] {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function createInstrumentationPlugin(
|
|
72
|
+
_routes: ResolvedRoute[],
|
|
73
|
+
_syncStreamPath: string | undefined
|
|
74
|
+
): AnyElysia {
|
|
75
|
+
return new Elysia({ name: "furin-production-instrumentation" });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function injectInstrumentationClient(html: string, _prefix: string): string {
|
|
79
|
+
return html;
|
|
80
|
+
}
|