@teyik0/furin 0.2.0-alpha.5 → 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/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/entry-template.d.ts +2 -0
- package/dist/build/entry-template.ts +3 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +6944 -5067
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +1 -0
- package/dist/cli/index.js +7874 -5971
- 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 +1 -1
- package/dist/config.js +2 -2
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +7 -6
- package/dist/furin.js +6547 -3187
- 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/cache/index.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr-ssg.d.ts +5 -1
- package/dist/server/cache/isr.d.ts +9 -0
- package/dist/server/cache/route-cache.d.ts +10 -8
- package/dist/server/cache/store-view.d.ts +7 -7
- 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/internal.d.ts +2 -0
- package/dist/server/internal.js +3 -3
- 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/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 +5 -9
- 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 -11
- 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/route-frame.d.ts +49 -0
- package/dist/shared/utils/index.d.ts +1 -1
- package/package.json +54 -12
- package/src/adapter/bun.ts +73 -16
- package/src/adapter/package.ts +3 -1
- package/src/adapter/static.ts +94 -48
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +22 -24
- package/src/build/entry-template.ts +3 -0
- package/src/build/hydrate.ts +33 -8
- package/src/build/index.ts +12 -0
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +7 -8
- package/src/build/scan-server.ts +3 -2
- package/src/build/ssg-cache.ts +7 -2
- package/src/build/types.ts +1 -0
- package/src/cli/index.ts +53 -22
- 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/devtools/devtools-element.js +884 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +185 -96
- 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/runtime.ts +32 -6
- package/src/server/cache/dev-loader.ts +70 -10
- package/src/server/cache/index.ts +7 -3
- package/src/server/cache/invalidation.ts +33 -15
- package/src/server/cache/isr-ssg.ts +12 -3
- package/src/server/cache/isr.ts +84 -9
- package/src/server/cache/route-cache.ts +49 -36
- package/src/server/cache/store-view.ts +7 -7
- 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 +1 -1
- package/src/server/internal.ts +2 -0
- 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 +10 -15
- 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 +155 -67
- package/src/server/render/template.ts +2 -1
- 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 +9 -27
- 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 -89
- 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 +137 -81
- 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/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
|
@@ -5,7 +5,13 @@ import {
|
|
|
5
5
|
revalidatePath,
|
|
6
6
|
revalidatePathForInstance,
|
|
7
7
|
} from "../cache/invalidation.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { pathWithoutSearch } from "../cache/route-cache.ts";
|
|
9
|
+
import {
|
|
10
|
+
currentInstrumentationRequest,
|
|
11
|
+
emitCacheInvalidated,
|
|
12
|
+
} from "../devtools/instrumentation.ts";
|
|
13
|
+
import { allInstances, withInstance } from "../instance.ts";
|
|
14
|
+
import { IS_DEV } from "../runtime-env.ts";
|
|
9
15
|
import { getAutoInvalidateRegistry } from "./registry.ts";
|
|
10
16
|
import type { InvalidationInput, InvalidationRule } from "./types.ts";
|
|
11
17
|
|
|
@@ -18,18 +24,17 @@ function statusFromResponseValue(responseValue: unknown): number | undefined {
|
|
|
18
24
|
return responseValue.status;
|
|
19
25
|
}
|
|
20
26
|
if (responseValue && typeof responseValue === "object" && "status" in responseValue) {
|
|
21
|
-
const status =
|
|
27
|
+
const { status } = responseValue as { status?: unknown };
|
|
22
28
|
if (typeof status === "number") {
|
|
23
29
|
return status;
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
if (responseValue && typeof responseValue === "object" && "code" in responseValue) {
|
|
27
|
-
const code =
|
|
33
|
+
const { code } = responseValue as { code?: unknown };
|
|
28
34
|
if (typeof code === "number") {
|
|
29
35
|
return code;
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
|
-
return;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export function isSuccessfulMutationResponse(
|
|
@@ -127,17 +132,38 @@ export function revalidateTag(tags: string | readonly string[]): boolean {
|
|
|
127
132
|
let deleted = false;
|
|
128
133
|
const purgedPaths = new Set<string>();
|
|
129
134
|
for (const instance of allInstances()) {
|
|
135
|
+
let instanceDeleted = false;
|
|
136
|
+
const instancePurgedPaths = new Set<string>();
|
|
130
137
|
// Registry paths are LOGICAL (unprefixed); the CDN caches the PHYSICAL
|
|
131
138
|
// request URL, so prefix each with the instance's mount prefix before
|
|
132
139
|
// queueing it for purge — otherwise a mounted app's `/admin/x` stays stale.
|
|
133
140
|
for (const path of getAutoInvalidateRegistry(instance).pathsForTags(tagList)) {
|
|
134
|
-
const
|
|
141
|
+
const logicalPath = pathWithoutSearch(path);
|
|
142
|
+
const result = revalidatePathForInstance(instance, logicalPath, "page", false);
|
|
135
143
|
deleted = result.deleted || deleted;
|
|
136
|
-
|
|
144
|
+
instanceDeleted = result.deleted || instanceDeleted;
|
|
145
|
+
purgedPaths.add(`${instance.prefix}${logicalPath}`);
|
|
146
|
+
instancePurgedPaths.add(logicalPath);
|
|
137
147
|
for (const purged of result.purgedPaths) {
|
|
138
148
|
purgedPaths.add(`${instance.prefix}${purged}`);
|
|
149
|
+
instancePurgedPaths.add(purged);
|
|
139
150
|
}
|
|
140
151
|
}
|
|
152
|
+
if (IS_DEV) {
|
|
153
|
+
withInstance(instance, () => {
|
|
154
|
+
const request = currentInstrumentationRequest();
|
|
155
|
+
const operationId = request === undefined ? null : request.operationId;
|
|
156
|
+
const requestId = request === undefined ? null : request.requestId;
|
|
157
|
+
emitCacheInvalidated({
|
|
158
|
+
deleted: instanceDeleted,
|
|
159
|
+
operationId,
|
|
160
|
+
purgedPaths: instancePurgedPaths.size,
|
|
161
|
+
reason: "tag",
|
|
162
|
+
requestId,
|
|
163
|
+
target: tagList.join(","),
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
141
167
|
}
|
|
142
168
|
// One batched CDN purge — the CDN sits in front of every mounted app, so
|
|
143
169
|
// physical paths from all instances go out together, deduped.
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
|
+
import { relative } from "node:path";
|
|
2
3
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry";
|
|
4
|
+
import {
|
|
5
|
+
currentInstrumentationRequest,
|
|
6
|
+
emitCacheInvalidated,
|
|
7
|
+
emitCacheAccess as emitInstrumentationCacheAccess,
|
|
8
|
+
} from "../devtools/instrumentation.ts";
|
|
3
9
|
import {
|
|
4
10
|
allStateBuckets,
|
|
5
11
|
currentInstance,
|
|
@@ -73,7 +79,7 @@ function createDevLoaderCache(name: string, index: Map<string, Set<string>>) {
|
|
|
73
79
|
name,
|
|
74
80
|
onDelete: (key, entry) => {
|
|
75
81
|
unindexEntryDependencies(index, key, entry.dependencies);
|
|
76
|
-
const urlPath =
|
|
82
|
+
const urlPath = urlPathWithSearchFromCacheKey(key);
|
|
77
83
|
if (urlPath) {
|
|
78
84
|
autoInvalidateRegistry.unregisterPath(urlPath);
|
|
79
85
|
}
|
|
@@ -103,8 +109,35 @@ const instanceDevLoaderState = instanceSlot((instance): DevLoaderState => {
|
|
|
103
109
|
};
|
|
104
110
|
});
|
|
105
111
|
|
|
112
|
+
function emitCacheAccess(
|
|
113
|
+
cache: "isr-loader" | "ssg-loader",
|
|
114
|
+
key: string,
|
|
115
|
+
entry: DevLoaderCacheEntry | undefined
|
|
116
|
+
): void {
|
|
117
|
+
const request = currentInstrumentationRequest();
|
|
118
|
+
const path = urlPathFromCacheKey(key);
|
|
119
|
+
if (request === undefined || path === null) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let outcome: "hit" | "miss" | "stale";
|
|
123
|
+
if (entry === undefined) {
|
|
124
|
+
outcome = "miss";
|
|
125
|
+
} else {
|
|
126
|
+
outcome = isDevLoaderCacheValid(entry) ? "hit" : "stale";
|
|
127
|
+
}
|
|
128
|
+
emitInstrumentationCacheAccess({
|
|
129
|
+
cache,
|
|
130
|
+
operationId: request.operationId,
|
|
131
|
+
outcome,
|
|
132
|
+
path,
|
|
133
|
+
requestId: request.requestId,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
106
137
|
export function getDevISRLoaderCache(key: string): DevLoaderCacheEntry | undefined {
|
|
107
|
-
|
|
138
|
+
const entry = instanceDevLoaderState().isr.cache.get(key);
|
|
139
|
+
emitCacheAccess("isr-loader", key, entry);
|
|
140
|
+
return entry;
|
|
108
141
|
}
|
|
109
142
|
|
|
110
143
|
export function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): void {
|
|
@@ -112,7 +145,9 @@ export function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): v
|
|
|
112
145
|
}
|
|
113
146
|
|
|
114
147
|
export function getDevSSGLoaderCache(key: string): DevLoaderCacheEntry | undefined {
|
|
115
|
-
|
|
148
|
+
const entry = instanceDevLoaderState().ssg.cache.get(key);
|
|
149
|
+
emitCacheAccess("ssg-loader", key, entry);
|
|
150
|
+
return entry;
|
|
116
151
|
}
|
|
117
152
|
|
|
118
153
|
export function setDevSSGLoaderCache(key: string, entry: DevLoaderCacheEntry): void {
|
|
@@ -120,11 +155,25 @@ export function setDevSSGLoaderCache(key: string, entry: DevLoaderCacheEntry): v
|
|
|
120
155
|
}
|
|
121
156
|
|
|
122
157
|
export function urlPathFromCacheKey(key: string): string | null {
|
|
123
|
-
const
|
|
158
|
+
const searchStart = key.indexOf("?");
|
|
159
|
+
const keyWithoutSearch = searchStart === -1 ? key : key.slice(0, searchStart);
|
|
160
|
+
const sep = keyWithoutSearch.lastIndexOf(":/");
|
|
124
161
|
if (sep === -1) {
|
|
125
162
|
return null;
|
|
126
163
|
}
|
|
127
|
-
return
|
|
164
|
+
return keyWithoutSearch.slice(sep + 1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function urlPathWithSearchFromCacheKey(key: string): string | null {
|
|
168
|
+
const urlPath = urlPathFromCacheKey(key);
|
|
169
|
+
if (urlPath === null) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const searchStart = key.indexOf("?");
|
|
173
|
+
if (searchStart === -1) {
|
|
174
|
+
return urlPath;
|
|
175
|
+
}
|
|
176
|
+
return `${urlPath}${key.slice(searchStart)}`;
|
|
128
177
|
}
|
|
129
178
|
|
|
130
179
|
export function invalidateDevLoaderCacheByPath(
|
|
@@ -157,9 +206,9 @@ export function invalidateDevLoaderCacheByPath(
|
|
|
157
206
|
handle.cache.delete(key);
|
|
158
207
|
cleared.push(key);
|
|
159
208
|
if (handle.kind === "isr") {
|
|
160
|
-
isr
|
|
209
|
+
isr += 1;
|
|
161
210
|
} else {
|
|
162
|
-
ssg
|
|
211
|
+
ssg += 1;
|
|
163
212
|
}
|
|
164
213
|
}
|
|
165
214
|
}
|
|
@@ -184,17 +233,28 @@ export function invalidateDevLoaderCacheBySource(filePath: string): InvalidateOu
|
|
|
184
233
|
if (isrEntry) {
|
|
185
234
|
state.isr.cache.delete(key);
|
|
186
235
|
cleared.push(key);
|
|
187
|
-
isr
|
|
236
|
+
isr += 1;
|
|
188
237
|
continue;
|
|
189
238
|
}
|
|
190
239
|
const ssgEntry = state.ssg.cache.get(key);
|
|
191
240
|
if (ssgEntry) {
|
|
192
241
|
state.ssg.cache.delete(key);
|
|
193
242
|
cleared.push(key);
|
|
194
|
-
ssg
|
|
243
|
+
ssg += 1;
|
|
195
244
|
}
|
|
196
245
|
}
|
|
197
246
|
|
|
247
|
+
const request = currentInstrumentationRequest();
|
|
248
|
+
const operationId = request === undefined ? null : request.operationId;
|
|
249
|
+
const requestId = request === undefined ? null : request.requestId;
|
|
250
|
+
emitCacheInvalidated({
|
|
251
|
+
deleted: cleared.length > 0,
|
|
252
|
+
operationId,
|
|
253
|
+
purgedPaths: cleared.length,
|
|
254
|
+
reason: "source",
|
|
255
|
+
requestId,
|
|
256
|
+
target: relative(process.cwd(), filePath).replaceAll("\\", "/"),
|
|
257
|
+
});
|
|
198
258
|
return { cleared, isr, ssg };
|
|
199
259
|
}
|
|
200
260
|
|
|
@@ -209,7 +269,7 @@ export function isDevLoaderCacheValid(entry: DevLoaderCacheEntry): boolean {
|
|
|
209
269
|
for (const dep of entry.dependencies) {
|
|
210
270
|
let mtimeMs: number;
|
|
211
271
|
try {
|
|
212
|
-
mtimeMs = statSync(dep)
|
|
272
|
+
({ mtimeMs } = statSync(dep));
|
|
213
273
|
} catch {
|
|
214
274
|
return false;
|
|
215
275
|
}
|
|
@@ -20,12 +20,16 @@ export {
|
|
|
20
20
|
_runWithRequestInvalidationScope,
|
|
21
21
|
callCachePurger,
|
|
22
22
|
consumePendingInvalidations,
|
|
23
|
-
getBuildId,
|
|
24
23
|
revalidatePath,
|
|
25
|
-
setBuildId,
|
|
26
24
|
setCachePurger,
|
|
27
25
|
} from "./invalidation";
|
|
28
|
-
export {
|
|
26
|
+
export {
|
|
27
|
+
deleteISRCache,
|
|
28
|
+
getISRCache,
|
|
29
|
+
isrCache,
|
|
30
|
+
setISRCache,
|
|
31
|
+
waitForPendingISRRevalidations,
|
|
32
|
+
} from "./isr";
|
|
29
33
|
export type { ISRCacheEntry, SsgCacheEntry } from "./isr-ssg";
|
|
30
34
|
export type { CacheInvalidator } from "./registry";
|
|
31
35
|
export { registerCacheInvalidator } from "./registry";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { createLogger } from "../context-logger";
|
|
2
|
+
import {
|
|
3
|
+
currentInstrumentationRequest,
|
|
4
|
+
emitCacheInvalidated,
|
|
5
|
+
} from "../devtools/instrumentation.ts";
|
|
2
6
|
import {
|
|
3
7
|
__clearInstanceRegistry,
|
|
4
8
|
allInstances,
|
|
@@ -9,23 +13,14 @@ import {
|
|
|
9
13
|
runWithInstanceScope,
|
|
10
14
|
withInstance,
|
|
11
15
|
} from "../instance.ts";
|
|
16
|
+
import { clearPprRouteCache } from "../render/ppr-route.ts";
|
|
17
|
+
import { IS_DEV } from "../runtime-env.ts";
|
|
12
18
|
import { clearDevLoaderCaches } from "./dev-loader";
|
|
13
|
-
import { isrRouteCache } from "./isr";
|
|
19
|
+
import { clearPendingISRRevalidations, isrRouteCache } from "./isr";
|
|
14
20
|
import { getCacheInvalidators } from "./registry";
|
|
15
21
|
import type { RevalidateType } from "./route-cache";
|
|
16
22
|
import { ssgRouteCache } from "./ssg";
|
|
17
23
|
|
|
18
|
-
// ── Build ID ─────────────────────────────────────────────────────────────────
|
|
19
|
-
// Lives on the furin instance — each mounted app reports its own build ID.
|
|
20
|
-
|
|
21
|
-
export function setBuildId(id: string): void {
|
|
22
|
-
currentInstance().buildId = id;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getBuildId(): string {
|
|
26
|
-
return currentInstance().buildId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
24
|
// ── Pending invalidations (server → client bridge) ───────────────────────────
|
|
30
25
|
// The per-request set lives in the instance request scope (see instance.ts);
|
|
31
26
|
// outside a request scope invalidations accumulate in a process-global set.
|
|
@@ -50,6 +45,10 @@ export function consumePendingInvalidations(): string[] {
|
|
|
50
45
|
return paths;
|
|
51
46
|
}
|
|
52
47
|
|
|
48
|
+
export function peekPendingInvalidations(): string[] {
|
|
49
|
+
return [..._activeInvalidationSet()];
|
|
50
|
+
}
|
|
51
|
+
|
|
53
52
|
// ── CDN purger hook ───────────────────────────────────────────────────────────
|
|
54
53
|
// Process-global on purpose: the CDN sits in front of every mounted app.
|
|
55
54
|
|
|
@@ -92,10 +91,13 @@ export function revalidatePath(path: string, type: RevalidateType): boolean {
|
|
|
92
91
|
for (const instance of allInstances()) {
|
|
93
92
|
const result = revalidatePathForInstance(instance, path, type);
|
|
94
93
|
deleted = result.deleted || deleted;
|
|
95
|
-
purgedPaths.push(
|
|
94
|
+
purgedPaths.push(`${instance.prefix}${path}`);
|
|
95
|
+
for (const purged of result.purgedPaths) {
|
|
96
|
+
purgedPaths.push(`${instance.prefix}${purged}`);
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
callCachePurger(dedupePaths(
|
|
100
|
+
callCachePurger(dedupePaths(purgedPaths));
|
|
99
101
|
return deleted;
|
|
100
102
|
}
|
|
101
103
|
|
|
@@ -109,7 +111,8 @@ export function revalidatePath(path: string, type: RevalidateType): boolean {
|
|
|
109
111
|
export function revalidatePathForInstance(
|
|
110
112
|
instance: FurinInstance,
|
|
111
113
|
path: string,
|
|
112
|
-
type: RevalidateType
|
|
114
|
+
type: RevalidateType,
|
|
115
|
+
emitPathEvent?: boolean
|
|
113
116
|
): { deleted: boolean; purgedPaths: string[] } {
|
|
114
117
|
_activeInvalidationSet().add(type === "layout" ? `${path}:layout` : path);
|
|
115
118
|
|
|
@@ -121,6 +124,19 @@ export function revalidatePathForInstance(
|
|
|
121
124
|
deleted = result.deleted || deleted;
|
|
122
125
|
purgedPaths.push(...result.purgedPaths);
|
|
123
126
|
}
|
|
127
|
+
if (IS_DEV && emitPathEvent !== false) {
|
|
128
|
+
const request = currentInstrumentationRequest();
|
|
129
|
+
const operationId = request === undefined ? null : request.operationId;
|
|
130
|
+
const requestId = request === undefined ? null : request.requestId;
|
|
131
|
+
emitCacheInvalidated({
|
|
132
|
+
deleted,
|
|
133
|
+
operationId,
|
|
134
|
+
purgedPaths: new Set(purgedPaths).size,
|
|
135
|
+
reason: "path",
|
|
136
|
+
requestId,
|
|
137
|
+
target: path,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
124
140
|
});
|
|
125
141
|
return { deleted, purgedPaths };
|
|
126
142
|
}
|
|
@@ -140,6 +156,8 @@ export function __resetCacheState(): void {
|
|
|
140
156
|
isrRouteCache(instance).clear();
|
|
141
157
|
ssgRouteCache(instance).clear();
|
|
142
158
|
clearDevLoaderCaches(instance);
|
|
159
|
+
clearPprRouteCache(instance);
|
|
160
|
+
clearPendingISRRevalidations(instance);
|
|
143
161
|
});
|
|
144
162
|
instance.buildId = "";
|
|
145
163
|
}
|
|
@@ -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,32 +1,107 @@
|
|
|
1
|
-
import { type FurinInstance, instanceSlot } from "../instance.ts";
|
|
1
|
+
import { allStateBuckets, type FurinInstance, instanceSlot } from "../instance.ts";
|
|
2
2
|
import { createHtmlRouteCache, type ISRCacheEntry } from "./isr-ssg";
|
|
3
3
|
import { registerCacheInvalidator } from "./registry";
|
|
4
4
|
import type { Cache } from "./route-cache";
|
|
5
5
|
import { createStoreView, type StoreView } from "./store-view";
|
|
6
6
|
|
|
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
|
+
}
|
|
16
|
+
|
|
7
17
|
// Per-instance ISR HTML cache — registered against the owning instance's
|
|
8
18
|
// invalidator map on first access.
|
|
9
|
-
const instanceIsrCache = instanceSlot((instance) => {
|
|
10
|
-
const
|
|
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
|
+
});
|
|
11
34
|
registerCacheInvalidator(cache, instance);
|
|
12
|
-
return cache;
|
|
35
|
+
return { cache, generations, pendingRevalidations };
|
|
13
36
|
});
|
|
14
37
|
|
|
15
38
|
export function isrRouteCache(instance?: FurinInstance): Cache<ISRCacheEntry> {
|
|
16
|
-
return instanceIsrCache(instance);
|
|
39
|
+
return instanceIsrCache(instance).cache;
|
|
17
40
|
}
|
|
18
41
|
|
|
19
42
|
/** Raw store view over the current instance's ISR cache. */
|
|
20
|
-
export const isrCache: StoreView<ISRCacheEntry> = createStoreView(
|
|
43
|
+
export const isrCache: StoreView<ISRCacheEntry> = createStoreView(
|
|
44
|
+
() => instanceIsrCache().cache.store
|
|
45
|
+
);
|
|
21
46
|
|
|
22
47
|
export function getISRCache(key: string): ISRCacheEntry | undefined {
|
|
23
|
-
return instanceIsrCache().get(key);
|
|
48
|
+
return instanceIsrCache().cache.get(key);
|
|
24
49
|
}
|
|
25
50
|
|
|
26
51
|
export function deleteISRCache(key: string): boolean {
|
|
27
|
-
return instanceIsrCache().delete(key);
|
|
52
|
+
return instanceIsrCache().cache.delete(key);
|
|
28
53
|
}
|
|
29
54
|
|
|
30
55
|
export function setISRCache(key: string, entry: ISRCacheEntry): void {
|
|
31
|
-
instanceIsrCache().set(key, entry);
|
|
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);
|
|
32
107
|
}
|
|
@@ -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
|
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// `ssgCache` / `isrCache` module exports working now that the real Map lives
|
|
3
3
|
// on the current furin instance (see server/instance.ts).
|
|
4
4
|
export interface StoreView<Entry> {
|
|
5
|
-
clear()
|
|
6
|
-
delete(key: string)
|
|
7
|
-
entries()
|
|
8
|
-
get(key: string)
|
|
9
|
-
has(key: string)
|
|
10
|
-
keys()
|
|
11
|
-
set(key: string, entry: 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
12
|
readonly size: number;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -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>();
|