@teyik0/furin 0.2.0-alpha.3 → 0.2.0-alpha.5
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/LICENSE +21 -21
- package/README.md +37 -33
- package/dist/adapter/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +114 -109
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +206 -156
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- 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 +30 -36
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/client/link.js +163 -16
- package/dist/client/router/abort.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +29 -0
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +37 -19
- package/dist/furin.js +982 -378
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/adapter.d.ts +62 -0
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/fingerprint.d.ts +6 -0
- package/dist/server/sync/index.d.ts +2 -2
- package/dist/server/sync/memory-adapter.d.ts +17 -0
- package/dist/server/sync/plugin.d.ts +12 -195
- package/dist/server/sync/response.d.ts +4 -0
- package/dist/server/sync/stream.d.ts +24 -5
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/README.md +13 -13
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +158 -152
- package/src/build/compile-entry.ts +114 -109
- package/src/build/entry-template.ts +206 -156
- package/src/build/hydrate.ts +342 -340
- package/src/build/index.ts +223 -152
- package/src/build/route-types.ts +145 -145
- package/src/build/scan-server.ts +111 -95
- package/src/build/server-routes-entry.ts +30 -36
- package/src/build/shared.ts +80 -80
- package/src/build/ssg-cache.ts +36 -32
- package/src/build/types.ts +125 -89
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/client/router/abort.ts +5 -0
- package/src/client/router/link-utils.ts +184 -184
- package/src/client/router/provider.tsx +883 -804
- package/src/client/router/sync-catch-up.ts +113 -0
- package/src/client/router/types.ts +276 -276
- package/src/client/sync.ts +98 -98
- package/src/client.ts +369 -369
- package/src/config.ts +14 -1
- package/src/furin.ts +619 -465
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +159 -134
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/dev-page-plugin.ts +454 -454
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/assemble.ts +160 -160
- package/src/server/render/isr.ts +323 -323
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +603 -585
- package/src/server/render/template.ts +57 -24
- package/src/server/router/plugin.ts +384 -384
- package/src/server/sync/adapter.ts +65 -0
- package/src/server/sync/config.ts +60 -29
- package/src/server/sync/fingerprint.ts +44 -0
- package/src/server/sync/index.ts +15 -14
- package/src/server/sync/memory-adapter.ts +196 -0
- package/src/server/sync/plugin.ts +199 -108
- package/src/server/sync/response.ts +77 -0
- package/src/server/sync/stream.ts +162 -144
- package/src/shared/deferred-ndjson.ts +7 -0
- package/src/shared/prefix.ts +38 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type FurinInstance, instanceSlot } from "../instance.ts";
|
|
2
|
+
|
|
1
3
|
export class AutoInvalidateRegistry {
|
|
2
4
|
private readonly pathToTags = new Map<string, Set<string>>();
|
|
3
5
|
private readonly tagToPaths = new Map<string, Set<string>>();
|
|
@@ -57,4 +59,24 @@ export class AutoInvalidateRegistry {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
const instanceAutoInvalidateRegistry = instanceSlot(() => new AutoInvalidateRegistry());
|
|
63
|
+
|
|
64
|
+
/** The current furin instance's registry (see server/instance.ts). */
|
|
65
|
+
export function getAutoInvalidateRegistry(instance?: FurinInstance): AutoInvalidateRegistry {
|
|
66
|
+
return instanceAutoInvalidateRegistry(instance);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Instance-scoped facade kept under the historical singleton name so call
|
|
71
|
+
* sites read the same — every method resolves the current instance's registry.
|
|
72
|
+
*/
|
|
73
|
+
export const autoInvalidateRegistry: Pick<
|
|
74
|
+
AutoInvalidateRegistry,
|
|
75
|
+
"registerLoaderTags" | "pathsForTags" | "unregisterPath" | "reset"
|
|
76
|
+
> = {
|
|
77
|
+
registerLoaderTags: (urlPath, tags) =>
|
|
78
|
+
instanceAutoInvalidateRegistry().registerLoaderTags(urlPath, tags),
|
|
79
|
+
pathsForTags: (tags) => instanceAutoInvalidateRegistry().pathsForTags(tags),
|
|
80
|
+
unregisterPath: (urlPath) => instanceAutoInvalidateRegistry().unregisterPath(urlPath),
|
|
81
|
+
reset: () => instanceAutoInvalidateRegistry().reset(),
|
|
82
|
+
};
|
|
@@ -1,134 +1,159 @@
|
|
|
1
|
-
import type { Context } from "elysia";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (responseValue && typeof responseValue === "object" && "
|
|
21
|
-
const
|
|
22
|
-
if (typeof
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import {
|
|
3
|
+
callCachePurger,
|
|
4
|
+
consumePendingInvalidations,
|
|
5
|
+
revalidatePath,
|
|
6
|
+
revalidatePathForInstance,
|
|
7
|
+
} from "../cache/invalidation.ts";
|
|
8
|
+
import { allInstances } from "../instance.ts";
|
|
9
|
+
import { getAutoInvalidateRegistry } from "./registry.ts";
|
|
10
|
+
import type { InvalidationInput, InvalidationRule } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
function toRules(input: InvalidationInput): readonly InvalidationRule[] {
|
|
13
|
+
return Array.isArray(input) ? input : [input as InvalidationRule];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function statusFromResponseValue(responseValue: unknown): number | undefined {
|
|
17
|
+
if (responseValue instanceof Response) {
|
|
18
|
+
return responseValue.status;
|
|
19
|
+
}
|
|
20
|
+
if (responseValue && typeof responseValue === "object" && "status" in responseValue) {
|
|
21
|
+
const status = (responseValue as { status?: unknown }).status;
|
|
22
|
+
if (typeof status === "number") {
|
|
23
|
+
return status;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (responseValue && typeof responseValue === "object" && "code" in responseValue) {
|
|
27
|
+
const code = (responseValue as { code?: unknown }).code;
|
|
28
|
+
if (typeof code === "number") {
|
|
29
|
+
return code;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isSuccessfulMutationResponse(
|
|
36
|
+
ctx: Pick<Context, "set"> & {
|
|
37
|
+
responseValue?: unknown;
|
|
38
|
+
response?: unknown;
|
|
39
|
+
}
|
|
40
|
+
): boolean {
|
|
41
|
+
const responseStatus =
|
|
42
|
+
statusFromResponseValue(ctx.responseValue) ?? statusFromResponseValue(ctx.response);
|
|
43
|
+
if (responseStatus !== undefined) {
|
|
44
|
+
return responseStatus >= 200 && responseStatus < 400;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const setStatus = ctx.set.status;
|
|
48
|
+
if (typeof setStatus === "number") {
|
|
49
|
+
return setStatus >= 200 && setStatus < 400;
|
|
50
|
+
}
|
|
51
|
+
if (typeof setStatus === "string") {
|
|
52
|
+
// Elysia allows string status codes (e.g. "Not Found"). We cannot map
|
|
53
|
+
// every possible string to its numeric code without the StatusMap, so we
|
|
54
|
+
// treat known client-error (4xx) and server-error (5xx) texts as failures
|
|
55
|
+
// and everything else as success (1xx, 2xx, 3xx, and any unknown string).
|
|
56
|
+
const errorStatusTexts = new Set([
|
|
57
|
+
"Bad Request",
|
|
58
|
+
"Unauthorized",
|
|
59
|
+
"Payment Required",
|
|
60
|
+
"Forbidden",
|
|
61
|
+
"Not Found",
|
|
62
|
+
"Method Not Allowed",
|
|
63
|
+
"Not Acceptable",
|
|
64
|
+
"Proxy Authentication Required",
|
|
65
|
+
"Request Timeout",
|
|
66
|
+
"Conflict",
|
|
67
|
+
"Gone",
|
|
68
|
+
"Length Required",
|
|
69
|
+
"Precondition Failed",
|
|
70
|
+
"Payload Too Large",
|
|
71
|
+
"URI Too Long",
|
|
72
|
+
"Unsupported Media Type",
|
|
73
|
+
"Range Not Satisfiable",
|
|
74
|
+
"Expectation Failed",
|
|
75
|
+
"I'm a teapot",
|
|
76
|
+
"Misdirected Request",
|
|
77
|
+
"Unprocessable Content",
|
|
78
|
+
"Locked",
|
|
79
|
+
"Failed Dependency",
|
|
80
|
+
"Too Early",
|
|
81
|
+
"Upgrade Required",
|
|
82
|
+
"Precondition Required",
|
|
83
|
+
"Too Many Requests",
|
|
84
|
+
"Enhance Your Calm",
|
|
85
|
+
"Request Header Fields Too Large",
|
|
86
|
+
"Unavailable For Legal Reasons",
|
|
87
|
+
"Internal Server Error",
|
|
88
|
+
"Not Implemented",
|
|
89
|
+
"Bad Gateway",
|
|
90
|
+
"Service Unavailable",
|
|
91
|
+
"Gateway Timeout",
|
|
92
|
+
"HTTP Version Not Supported",
|
|
93
|
+
"Variant Also Negotiates",
|
|
94
|
+
"Insufficient Storage",
|
|
95
|
+
"Loop Detected",
|
|
96
|
+
"Not Extended",
|
|
97
|
+
"Network Authentication Required",
|
|
98
|
+
]);
|
|
99
|
+
return !errorStatusTexts.has(setStatus);
|
|
100
|
+
}
|
|
101
|
+
// No explicit status was set — default to success (200).
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function appendPendingInvalidationHeader(set: Context["set"]): string[] {
|
|
106
|
+
const pending = consumePendingInvalidations();
|
|
107
|
+
if (pending.length === 0) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const headerName = "x-furin-revalidate";
|
|
112
|
+
const existing = set.headers[headerName];
|
|
113
|
+
set.headers[headerName] =
|
|
114
|
+
typeof existing === "string" && existing.length > 0
|
|
115
|
+
? `${existing},${pending.join(",")}`
|
|
116
|
+
: pending.join(",");
|
|
117
|
+
return pending;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function revalidateTag(tags: string | readonly string[]): boolean {
|
|
121
|
+
const tagList = typeof tags === "string" ? [tags] : [...tags];
|
|
122
|
+
// Tags are cross-app by design: with several mounted furin instances a
|
|
123
|
+
// shared mutation must be able to invalidate pages rendered by any of them.
|
|
124
|
+
// But each instance's tag-registered paths are evicted from THAT instance's
|
|
125
|
+
// caches only — the cross-app fan-out of `revalidatePath` would also evict
|
|
126
|
+
// a sibling app's unrelated page that merely shares the pathname.
|
|
127
|
+
let deleted = false;
|
|
128
|
+
const purgedPaths = new Set<string>();
|
|
129
|
+
for (const instance of allInstances()) {
|
|
130
|
+
// Registry paths are LOGICAL (unprefixed); the CDN caches the PHYSICAL
|
|
131
|
+
// request URL, so prefix each with the instance's mount prefix before
|
|
132
|
+
// queueing it for purge — otherwise a mounted app's `/admin/x` stays stale.
|
|
133
|
+
for (const path of getAutoInvalidateRegistry(instance).pathsForTags(tagList)) {
|
|
134
|
+
const result = revalidatePathForInstance(instance, path, "page");
|
|
135
|
+
deleted = result.deleted || deleted;
|
|
136
|
+
purgedPaths.add(`${instance.prefix}${path}`);
|
|
137
|
+
for (const purged of result.purgedPaths) {
|
|
138
|
+
purgedPaths.add(`${instance.prefix}${purged}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// One batched CDN purge — the CDN sits in front of every mounted app, so
|
|
143
|
+
// physical paths from all instances go out together, deduped.
|
|
144
|
+
callCachePurger([...purgedPaths]);
|
|
145
|
+
return deleted;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function runInvalidationRules(input: InvalidationInput): boolean {
|
|
149
|
+
let deleted = false;
|
|
150
|
+
for (const rule of toRules(input)) {
|
|
151
|
+
if ("path" in rule && rule.path) {
|
|
152
|
+
deleted = revalidatePath(rule.path, rule.type) || deleted;
|
|
153
|
+
}
|
|
154
|
+
if (rule.tags && rule.tags.length > 0) {
|
|
155
|
+
deleted = revalidateTag(rule.tags) || deleted;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return deleted;
|
|
159
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
2
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry";
|
|
3
|
+
import {
|
|
4
|
+
allStateBuckets,
|
|
5
|
+
currentInstance,
|
|
6
|
+
type FurinInstance,
|
|
7
|
+
instanceSlot,
|
|
8
|
+
withInstance,
|
|
9
|
+
} from "../instance.ts";
|
|
3
10
|
import { registerCacheInvalidator } from "./registry";
|
|
4
11
|
import { createRouteCache, type RevalidateType } from "./route-cache";
|
|
5
12
|
|
|
@@ -18,42 +25,54 @@ export interface InvalidateOutcome {
|
|
|
18
25
|
ssg: number;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
|
-
const sourceFileToCacheKeys = new Map<string, Set<string>>();
|
|
22
|
-
|
|
23
28
|
interface CacheKindHandle {
|
|
24
29
|
cache: ReturnType<typeof createDevLoaderCache>;
|
|
25
30
|
kind: "isr" | "ssg";
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
interface DevLoaderState {
|
|
34
|
+
isr: CacheKindHandle;
|
|
35
|
+
sourceFileToCacheKeys: Map<string, Set<string>>;
|
|
36
|
+
ssg: CacheKindHandle;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function indexEntryDependencies(
|
|
40
|
+
index: Map<string, Set<string>>,
|
|
41
|
+
cacheKey: string,
|
|
42
|
+
deps: string[]
|
|
43
|
+
): void {
|
|
29
44
|
for (const dep of deps) {
|
|
30
|
-
let bucket =
|
|
45
|
+
let bucket = index.get(dep);
|
|
31
46
|
if (!bucket) {
|
|
32
47
|
bucket = new Set<string>();
|
|
33
|
-
|
|
48
|
+
index.set(dep, bucket);
|
|
34
49
|
}
|
|
35
50
|
bucket.add(cacheKey);
|
|
36
51
|
}
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
function unindexEntryDependencies(
|
|
54
|
+
function unindexEntryDependencies(
|
|
55
|
+
index: Map<string, Set<string>>,
|
|
56
|
+
cacheKey: string,
|
|
57
|
+
deps: string[]
|
|
58
|
+
): void {
|
|
40
59
|
for (const dep of deps) {
|
|
41
|
-
const bucket =
|
|
60
|
+
const bucket = index.get(dep);
|
|
42
61
|
if (!bucket) {
|
|
43
62
|
continue;
|
|
44
63
|
}
|
|
45
64
|
bucket.delete(cacheKey);
|
|
46
65
|
if (bucket.size === 0) {
|
|
47
|
-
|
|
66
|
+
index.delete(dep);
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
}
|
|
51
70
|
|
|
52
|
-
function createDevLoaderCache(name: string) {
|
|
71
|
+
function createDevLoaderCache(name: string, index: Map<string, Set<string>>) {
|
|
53
72
|
return createRouteCache<DevLoaderCacheEntry>({
|
|
54
73
|
name,
|
|
55
74
|
onDelete: (key, entry) => {
|
|
56
|
-
unindexEntryDependencies(key, entry.dependencies);
|
|
75
|
+
unindexEntryDependencies(index, key, entry.dependencies);
|
|
57
76
|
const urlPath = urlPathFromCacheKey(key);
|
|
58
77
|
if (urlPath) {
|
|
59
78
|
autoInvalidateRegistry.unregisterPath(urlPath);
|
|
@@ -61,38 +80,43 @@ function createDevLoaderCache(name: string) {
|
|
|
61
80
|
},
|
|
62
81
|
onSet: (key, entry, previous) => {
|
|
63
82
|
if (previous) {
|
|
64
|
-
unindexEntryDependencies(key, previous.dependencies);
|
|
83
|
+
unindexEntryDependencies(index, key, previous.dependencies);
|
|
65
84
|
}
|
|
66
|
-
indexEntryDependencies(key, entry.dependencies);
|
|
85
|
+
indexEntryDependencies(index, key, entry.dependencies);
|
|
67
86
|
},
|
|
68
87
|
pathFromKey: urlPathFromCacheKey,
|
|
69
88
|
});
|
|
70
89
|
}
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
// Per-instance dev loader caches + source-dependency index — two furin
|
|
92
|
+
// instances in one dev process must not invalidate each other's loader data.
|
|
93
|
+
const instanceDevLoaderState = instanceSlot((instance): DevLoaderState => {
|
|
94
|
+
const sourceFileToCacheKeys = new Map<string, Set<string>>();
|
|
95
|
+
const isrCache = createDevLoaderCache("render:dev-isr-loader", sourceFileToCacheKeys);
|
|
96
|
+
const ssgCache = createDevLoaderCache("render:dev-ssg-loader", sourceFileToCacheKeys);
|
|
97
|
+
registerCacheInvalidator(isrCache, instance);
|
|
98
|
+
registerCacheInvalidator(ssgCache, instance);
|
|
99
|
+
return {
|
|
100
|
+
isr: { cache: isrCache, kind: "isr" },
|
|
101
|
+
sourceFileToCacheKeys,
|
|
102
|
+
ssg: { cache: ssgCache, kind: "ssg" },
|
|
103
|
+
};
|
|
104
|
+
});
|
|
81
105
|
|
|
82
106
|
export function getDevISRLoaderCache(key: string): DevLoaderCacheEntry | undefined {
|
|
83
|
-
return
|
|
107
|
+
return instanceDevLoaderState().isr.cache.get(key);
|
|
84
108
|
}
|
|
85
109
|
|
|
86
110
|
export function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): void {
|
|
87
|
-
|
|
111
|
+
instanceDevLoaderState().isr.cache.set(key, entry);
|
|
88
112
|
}
|
|
89
113
|
|
|
90
114
|
export function getDevSSGLoaderCache(key: string): DevLoaderCacheEntry | undefined {
|
|
91
|
-
return
|
|
115
|
+
return instanceDevLoaderState().ssg.cache.get(key);
|
|
92
116
|
}
|
|
93
117
|
|
|
94
118
|
export function setDevSSGLoaderCache(key: string, entry: DevLoaderCacheEntry): void {
|
|
95
|
-
|
|
119
|
+
instanceDevLoaderState().ssg.cache.set(key, entry);
|
|
96
120
|
}
|
|
97
121
|
|
|
98
122
|
export function urlPathFromCacheKey(key: string): string | null {
|
|
@@ -107,6 +131,7 @@ export function invalidateDevLoaderCacheByPath(
|
|
|
107
131
|
path: string,
|
|
108
132
|
type: RevalidateType
|
|
109
133
|
): InvalidateOutcome {
|
|
134
|
+
const state = instanceDevLoaderState();
|
|
110
135
|
const cleared: string[] = [];
|
|
111
136
|
let isr = 0;
|
|
112
137
|
let ssg = 0;
|
|
@@ -119,7 +144,7 @@ export function invalidateDevLoaderCacheByPath(
|
|
|
119
144
|
return urlPath === path || urlPath.startsWith(prefix);
|
|
120
145
|
};
|
|
121
146
|
|
|
122
|
-
for (const handle of [
|
|
147
|
+
for (const handle of [state.isr, state.ssg]) {
|
|
123
148
|
for (const key of [...handle.cache.keys()]) {
|
|
124
149
|
const urlPath = urlPathFromCacheKey(key);
|
|
125
150
|
if (urlPath === null || !matches(urlPath)) {
|
|
@@ -143,7 +168,8 @@ export function invalidateDevLoaderCacheByPath(
|
|
|
143
168
|
}
|
|
144
169
|
|
|
145
170
|
export function invalidateDevLoaderCacheBySource(filePath: string): InvalidateOutcome {
|
|
146
|
-
const
|
|
171
|
+
const state = instanceDevLoaderState();
|
|
172
|
+
const keys = state.sourceFileToCacheKeys.get(filePath);
|
|
147
173
|
if (!keys || keys.size === 0) {
|
|
148
174
|
return { cleared: [], isr: 0, ssg: 0 };
|
|
149
175
|
}
|
|
@@ -154,16 +180,16 @@ export function invalidateDevLoaderCacheBySource(filePath: string): InvalidateOu
|
|
|
154
180
|
|
|
155
181
|
const snapshot = [...keys];
|
|
156
182
|
for (const key of snapshot) {
|
|
157
|
-
const isrEntry =
|
|
183
|
+
const isrEntry = state.isr.cache.get(key);
|
|
158
184
|
if (isrEntry) {
|
|
159
|
-
|
|
185
|
+
state.isr.cache.delete(key);
|
|
160
186
|
cleared.push(key);
|
|
161
187
|
isr++;
|
|
162
188
|
continue;
|
|
163
189
|
}
|
|
164
|
-
const ssgEntry =
|
|
190
|
+
const ssgEntry = state.ssg.cache.get(key);
|
|
165
191
|
if (ssgEntry) {
|
|
166
|
-
|
|
192
|
+
state.ssg.cache.delete(key);
|
|
167
193
|
cleared.push(key);
|
|
168
194
|
ssg++;
|
|
169
195
|
}
|
|
@@ -195,17 +221,30 @@ export function isDevLoaderCacheValid(entry: DevLoaderCacheEntry): boolean {
|
|
|
195
221
|
}
|
|
196
222
|
|
|
197
223
|
export function getAllDevISRLoaderEntries(): [string, DevLoaderCacheEntry][] {
|
|
198
|
-
return [...
|
|
224
|
+
return [...instanceDevLoaderState().isr.cache.entries()];
|
|
199
225
|
}
|
|
200
226
|
|
|
201
227
|
export function getAllDevSSGLoaderEntries(): [string, DevLoaderCacheEntry][] {
|
|
202
|
-
return [...
|
|
228
|
+
return [...instanceDevLoaderState().ssg.cache.entries()];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** @internal — clears dev loader caches for `instance` (default: current). */
|
|
232
|
+
export function clearDevLoaderCaches(instance?: FurinInstance): void {
|
|
233
|
+
const target = instance ?? currentInstance();
|
|
234
|
+
const state = instanceDevLoaderState(target);
|
|
235
|
+
// `.clear()` fires onDelete per entry, which unregisters the path from the
|
|
236
|
+
// auto-invalidate registry via the `currentInstance()`-scoped facade — bind
|
|
237
|
+
// the scope here so the unregistration hits the cleared instance's registry
|
|
238
|
+
// (re-entering an already-active identical scope is harmless).
|
|
239
|
+
withInstance(target, () => {
|
|
240
|
+
state.isr.cache.clear();
|
|
241
|
+
state.ssg.cache.clear();
|
|
242
|
+
});
|
|
243
|
+
state.sourceFileToCacheKeys.clear();
|
|
203
244
|
}
|
|
204
245
|
|
|
205
246
|
export function __resetDevLoaderCacheState(): void {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
registerCacheInvalidator(devISRLoaderCache);
|
|
210
|
-
registerCacheInvalidator(devSSGLoaderCache);
|
|
247
|
+
for (const instance of allStateBuckets()) {
|
|
248
|
+
clearDevLoaderCaches(instance);
|
|
249
|
+
}
|
|
211
250
|
}
|