@teyik0/furin 0.8.0-alpha.0 → 0.9.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/adapter/bun/app.d.ts +1 -0
- package/dist/adapter/bun.d.ts +3 -1
- package/dist/adapter/runtime-build.d.ts +8 -5
- package/dist/adapter/vercel.js +8 -8
- package/dist/build/client.d.ts +2 -2
- package/dist/build/discover-mounts-process.d.ts +1 -1
- package/dist/build/discover-pages-process.d.ts +1 -0
- package/dist/build/discover-pages.d.ts +11 -0
- package/dist/build/discovery-module.d.ts +3 -0
- package/dist/build/discovery-plugins.d.ts +34 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.ts +6 -1
- package/dist/build/hydrate.d.ts +3 -2
- package/dist/build/index.js +7688 -8458
- package/dist/build/preload-manifest.d.ts +2 -2
- package/dist/build/route-metadata.d.ts +31 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/shared.d.ts +2 -2
- package/dist/build/types.d.ts +11 -0
- package/dist/cli/dev-worker.d.ts +1 -0
- package/dist/cli/dev-worker.ts +123 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/index.js +7811 -8477
- package/dist/client/browser-events-runtime.d.ts +2 -2
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/chunks/{client-brdfd773.js → client-rjhxgt64.js} +187 -4
- package/dist/client/dev-error-overlay.ts +18 -1
- package/dist/client/link.js +110 -156
- package/dist/client/query-store.d.ts +5 -0
- package/dist/client/router/navigation-controller.d.ts +2 -0
- package/dist/client/router/use-fetch-interception.d.ts +1 -1
- package/dist/client/router/use-sync-stream.d.ts +1 -1
- package/dist/client/{router/sync-catch-up.d.ts → sync-catch-up.d.ts} +5 -3
- package/dist/client/sync-client.d.ts +74 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +533 -145
- package/dist/config.d.ts +6 -1
- package/dist/config.js +3 -1
- package/dist/define-route.d.ts +3 -3
- package/dist/furin.d.ts +2 -1
- package/dist/furin.js +1119 -346
- package/dist/plugin/index.js +5 -5
- package/dist/plugin/route-registry.d.ts +22 -2
- package/dist/rsc/build/index.d.ts +4 -3
- package/dist/server/dev/server-only-module.d.ts +5 -0
- package/dist/server/internal.js +201 -91
- package/dist/server/logging/ingest-plugin.d.ts +1 -2
- package/dist/server/production-server.js +36 -33
- package/dist/server/server-entry.d.ts +5 -0
- package/dist/server/server-entry.js +36 -0
- package/dist/server/static-export.js +201 -91
- package/dist/server/sync/adapter.d.ts +4 -3
- package/dist/server/sync/config.d.ts +7 -0
- package/dist/server/sync/connection.d.ts +13 -0
- package/dist/server/sync/drizzle/index.js +5 -4
- package/dist/server/sync/index.d.ts +3 -0
- package/dist/server/sync/index.js +1361 -243
- package/dist/server/sync/invalidate-sync.d.ts +6 -2
- package/dist/server/sync/local-client.d.ts +9 -0
- package/dist/server/sync/postgres/index.d.ts +1 -1
- package/dist/server/sync/postgres/index.js +2 -2
- package/dist/server/sync/prisma/index.js +2 -2
- package/dist/server/sync/redis/index.d.ts +1 -1
- package/dist/server/sync/redis/index.js +4 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/runtime.d.ts +3 -0
- package/dist/server/sync/sqlite/index.d.ts +1 -1
- package/dist/server/sync/sqlite/index.js +3 -2
- package/dist/shared/browser-events.d.ts +4 -0
- package/dist/sync-client.d.ts +3 -0
- package/dist/sync-client.js +1600 -0
- package/package.json +12 -7
- package/src/adapter/README.md +7 -0
- package/src/adapter/build.ts +34 -33
- package/src/adapter/bun/app.ts +5 -0
- package/src/adapter/bun/server.ts +2 -2
- package/src/adapter/bun.ts +18 -2
- package/src/adapter/furin-app.d.ts +1 -0
- package/src/adapter/package.ts +1 -0
- package/src/adapter/runtime-build.ts +18 -12
- package/src/adapter/static.ts +17 -13
- package/src/build/client.ts +7 -5
- package/src/build/discover-mounts-process.ts +5 -1
- package/src/build/discover-pages-process.ts +151 -0
- package/src/build/discover-pages.ts +69 -0
- package/src/build/discovery-module.ts +70 -0
- package/src/build/discovery-plugins.ts +101 -0
- package/src/build/elysia-aot-worker.ts +9 -8
- package/src/build/elysia-aot.ts +110 -75
- package/src/build/entry-template.ts +6 -1
- package/src/build/hydrate.ts +11 -8
- package/src/build/index.ts +6 -50
- package/src/build/preload-manifest.ts +3 -3
- package/src/build/route-metadata.ts +90 -0
- package/src/build/route-types.ts +1 -1
- package/src/build/shared.ts +6 -8
- package/src/build/types.ts +9 -0
- package/src/cli/config.ts +4 -0
- package/src/cli/dev-worker.ts +123 -0
- package/src/cli/dev.ts +91 -0
- package/src/cli/index.ts +24 -1
- package/src/client/browser-events-runtime.ts +97 -23
- package/src/client/browser-events.ts +8 -0
- package/src/client/dev-error-overlay.ts +18 -1
- package/src/client/query-store.ts +54 -3
- package/src/client/router/navigation-controller.ts +45 -12
- package/src/client/router/provider.tsx +6 -2
- package/src/client/router/use-fetch-interception.ts +1 -1
- package/src/client/router/use-sync-stream.ts +96 -44
- package/src/client/{router/sync-catch-up.ts → sync-catch-up.ts} +28 -12
- package/src/client/sync-client.ts +528 -0
- package/src/client/sync.ts +11 -4
- package/src/client.ts +10 -0
- package/src/config.ts +17 -10
- package/src/furin.ts +5 -0
- package/src/plugin/route-registry.ts +53 -7
- package/src/rsc/build/index.ts +6 -3
- package/src/server/browser-events/plugin.ts +79 -25
- package/src/server/dev/rewrite-module-specifiers.ts +2 -1
- package/src/server/dev/server-only-module.ts +23 -0
- package/src/server/dev/symbolicate.ts +4 -3
- package/src/server/dev-page-imports.ts +3 -1
- package/src/server/dev-page-plugin.ts +18 -1
- package/src/server/logging/ingest-plugin.ts +3 -9
- package/src/server/server-entry.ts +39 -0
- package/src/server/sync/adapter.ts +7 -3
- package/src/server/sync/config.ts +12 -6
- package/src/server/sync/connection.ts +71 -0
- package/src/server/sync/index.ts +3 -0
- package/src/server/sync/invalidate-sync.ts +30 -5
- package/src/server/sync/local-client.ts +84 -0
- package/src/server/sync/plugin.ts +27 -20
- package/src/server/sync/postgres/index.ts +9 -2
- package/src/server/sync/redis/index.ts +5 -1
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/runtime.ts +56 -18
- package/src/server/sync/sqlite/index.ts +6 -2
- package/src/server/sync/stream.ts +17 -5
- package/src/shared/browser-events.ts +1 -1
- package/src/sync-client.ts +14 -0
- package/dist/server/logger.d.ts +0 -10
- package/src/server/logger.ts +0 -34
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { log } from "evlog";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
+
import type { BrowserEventFor } from "../../shared/browser-events.ts";
|
|
3
4
|
import { queryTag, queryTags } from "../../shared/sync-query.ts";
|
|
4
|
-
import { subscribeBrowserEvent } from "../browser-events.ts";
|
|
5
|
+
import { setBrowserSyncAuthentication, subscribeBrowserEvent } from "../browser-events.ts";
|
|
5
6
|
import type { QueryStore } from "../query-store.ts";
|
|
7
|
+
import {
|
|
8
|
+
createSyncCatchUp,
|
|
9
|
+
type InvalidationRefresh,
|
|
10
|
+
type SyncChangePagePayload,
|
|
11
|
+
} from "../sync-catch-up.ts";
|
|
6
12
|
import {
|
|
7
13
|
applyRevalidateEntries,
|
|
8
14
|
normalizeHref,
|
|
@@ -10,11 +16,6 @@ import {
|
|
|
10
16
|
toLogical,
|
|
11
17
|
} from "./link-utils.ts";
|
|
12
18
|
import type { NavigationController } from "./navigation-controller.ts";
|
|
13
|
-
import {
|
|
14
|
-
createSyncCatchUp,
|
|
15
|
-
type InvalidationRefresh,
|
|
16
|
-
type SyncChangePagePayload,
|
|
17
|
-
} from "./sync-catch-up.ts";
|
|
18
19
|
import type { RouterState } from "./types.ts";
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -42,6 +43,24 @@ export function useSyncStream(options: {
|
|
|
42
43
|
: `${basePath}/${syncPath}`;
|
|
43
44
|
let unsubscribe: (() => void) | undefined;
|
|
44
45
|
let disposed = false;
|
|
46
|
+
let requestController = new AbortController();
|
|
47
|
+
let contextChanged = false;
|
|
48
|
+
let session: string | undefined;
|
|
49
|
+
const clearContext = () => {
|
|
50
|
+
contextChanged = true;
|
|
51
|
+
queries.clear();
|
|
52
|
+
controller.invalidateContext();
|
|
53
|
+
};
|
|
54
|
+
const observeSession = (response: Response) => {
|
|
55
|
+
const identity = response.headers.get("x-furin-sync-session");
|
|
56
|
+
if (identity === null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (session !== undefined && identity !== session) {
|
|
60
|
+
clearContext();
|
|
61
|
+
}
|
|
62
|
+
session = identity;
|
|
63
|
+
};
|
|
45
64
|
const applyInvalidations = (entries: readonly string[]) => {
|
|
46
65
|
if (disposed) {
|
|
47
66
|
return;
|
|
@@ -61,53 +80,84 @@ export function useSyncStream(options: {
|
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
82
|
};
|
|
64
|
-
const
|
|
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
|
-
|
|
83
|
+
const createRecovery = () =>
|
|
84
|
+
createSyncCatchUp({
|
|
85
|
+
fetchPage: async (after) => {
|
|
86
|
+
const url = new URL(`${changesUrl}/changes`, window.location.origin);
|
|
87
|
+
if (after !== undefined) {
|
|
88
|
+
url.searchParams.set("after", after);
|
|
89
|
+
}
|
|
90
|
+
const { signal } = requestController;
|
|
91
|
+
const response = await window.fetch(url, { signal });
|
|
92
|
+
signal.throwIfAborted();
|
|
93
|
+
if (response.status === 401 || response.status === 403) {
|
|
94
|
+
clearContext();
|
|
95
|
+
setBrowserSyncAuthentication(false);
|
|
96
|
+
}
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw new Error(`Sync catch-up failed with status ${response.status}`);
|
|
99
|
+
}
|
|
100
|
+
const page = (await response.json()) as SyncChangePagePayload;
|
|
101
|
+
signal.throwIfAborted();
|
|
102
|
+
observeSession(response);
|
|
103
|
+
return page;
|
|
104
|
+
},
|
|
105
|
+
onInvalidations: applyInvalidations,
|
|
106
|
+
onReset: () => {
|
|
107
|
+
if (!disposed) {
|
|
108
|
+
queries.invalidateAll();
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
onQueries: (identities) => {
|
|
112
|
+
queries.invalidate(identities);
|
|
113
|
+
const tags = new Set(identities.map(queryTag));
|
|
114
|
+
const affected = (snapshot: RouterState) =>
|
|
115
|
+
snapshot.querySeeds?.some((seed) =>
|
|
116
|
+
queryTags(seed.identity).some((tag) => tags.has(tag))
|
|
117
|
+
) === true;
|
|
118
|
+
controller.invalidateQueries(affected);
|
|
119
|
+
if (autoRefresh && affected(controller.getSnapshot().state)) {
|
|
120
|
+
invalidationRefresh.run();
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
let catchUp = createRecovery();
|
|
95
125
|
const recover = () => {
|
|
96
126
|
if (disposed) {
|
|
97
127
|
return;
|
|
98
128
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
const current = catchUp;
|
|
130
|
+
current
|
|
131
|
+
.catchUp()
|
|
132
|
+
.then(() => {
|
|
133
|
+
if (!disposed && catchUp === current && contextChanged) {
|
|
134
|
+
contextChanged = false;
|
|
135
|
+
queries.invalidateAll();
|
|
136
|
+
applyInvalidations(["/:layout"]);
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
.catch((error: unknown) => {
|
|
140
|
+
if (!disposed) {
|
|
141
|
+
log.warn({ action: "sync_catch_up_failed", error: String(error) });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
104
144
|
};
|
|
105
|
-
const onSync = (event:
|
|
145
|
+
const onSync = (event: BrowserEventFor<"sync">) => {
|
|
146
|
+
if (event.data.context === "changed") {
|
|
147
|
+
requestController.abort();
|
|
148
|
+
requestController = new AbortController();
|
|
149
|
+
catchUp.close();
|
|
150
|
+
catchUp = createRecovery();
|
|
151
|
+
clearContext();
|
|
152
|
+
recover();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
106
155
|
if (typeof event.data.cursor !== "string") {
|
|
107
156
|
log.warn({ action: "sync_invalid_event", event: "browser-events.sync" });
|
|
108
157
|
return;
|
|
109
158
|
}
|
|
110
|
-
|
|
159
|
+
// Notifications do not prove the rendered snapshot includes earlier writes.
|
|
160
|
+
// Recover from zero first; only successful HTTP recovery advances the cursor.
|
|
111
161
|
recover();
|
|
112
162
|
};
|
|
113
163
|
const connect = () => {
|
|
@@ -123,6 +173,8 @@ export function useSyncStream(options: {
|
|
|
123
173
|
connect();
|
|
124
174
|
return () => {
|
|
125
175
|
disposed = true;
|
|
176
|
+
requestController.abort();
|
|
177
|
+
catchUp.close();
|
|
126
178
|
unsubscribe?.();
|
|
127
179
|
};
|
|
128
180
|
}, [syncPath, basePath, invalidationRefresh, autoRefresh, queries, controller]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// biome-ignore-all lint/performance/noAwaitInLoops: sync catch-up pages must be fetched sequentially by cursor
|
|
2
|
-
import type { SyncInvalidation } from "
|
|
3
|
-
import { encodeInvalidationEntry } from "
|
|
4
|
-
import { type QueryIdentity, queryFromTag } from "
|
|
2
|
+
import type { SyncInvalidation } from "../server/sync/adapter.ts";
|
|
3
|
+
import { encodeInvalidationEntry } from "../shared/invalidation-header.ts";
|
|
4
|
+
import { type QueryIdentity, queryFromTag } from "../shared/sync-query.ts";
|
|
5
5
|
|
|
6
6
|
interface SyncChangePayload {
|
|
7
7
|
cursor: string;
|
|
8
8
|
invalidations: readonly (string | SyncInvalidation)[];
|
|
9
|
-
queries?: readonly
|
|
9
|
+
queries?: readonly QueryIdentity[];
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface SyncChangePagePayload {
|
|
@@ -19,7 +19,7 @@ export interface SyncChangePagePayload {
|
|
|
19
19
|
interface SyncCatchUpOptions {
|
|
20
20
|
fetchPage: (after: string | undefined) => Promise<SyncChangePagePayload>;
|
|
21
21
|
onInvalidations: (invalidations: readonly string[]) => void;
|
|
22
|
-
onQueries?: (identities: readonly
|
|
22
|
+
onQueries?: (identities: readonly QueryIdentity[]) => void;
|
|
23
23
|
onReset?: () => void;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -57,6 +57,7 @@ function changeInvalidations(change: SyncChangePayload): {
|
|
|
57
57
|
|
|
58
58
|
export interface SyncCatchUp {
|
|
59
59
|
catchUp: () => Promise<void>;
|
|
60
|
+
close: () => void;
|
|
60
61
|
cursor: () => string | undefined;
|
|
61
62
|
seed: (cursor: string) => void;
|
|
62
63
|
}
|
|
@@ -114,6 +115,7 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
114
115
|
let requested = false;
|
|
115
116
|
let lastReset = Number.NEGATIVE_INFINITY;
|
|
116
117
|
let pendingReset: ReturnType<typeof setTimeout> | undefined;
|
|
118
|
+
let closed = false;
|
|
117
119
|
|
|
118
120
|
const refreshAfterReset = () => {
|
|
119
121
|
pendingReset = undefined;
|
|
@@ -141,25 +143,35 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
141
143
|
let page: SyncChangePagePayload;
|
|
142
144
|
do {
|
|
143
145
|
page = await options.fetchPage(currentCursor ?? "0");
|
|
146
|
+
if (closed) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
144
149
|
if (page.reset) {
|
|
145
150
|
currentCursor = page.cursor;
|
|
146
151
|
scheduleResetRefresh();
|
|
147
152
|
break;
|
|
148
153
|
}
|
|
149
154
|
for (const change of page.changes) {
|
|
150
|
-
|
|
151
|
-
options.onInvalidations(paths);
|
|
152
|
-
if (queries.length > 0) {
|
|
153
|
-
options.onQueries?.(queries);
|
|
154
|
-
}
|
|
155
|
+
applyChange(change);
|
|
155
156
|
}
|
|
156
157
|
currentCursor = page.cursor;
|
|
157
158
|
} while (page.hasMore);
|
|
158
|
-
} while (requested);
|
|
159
|
+
} while (requested && !closed);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const applyChange = (change: SyncChangePayload) => {
|
|
163
|
+
const { paths, queries } = changeInvalidations(change);
|
|
164
|
+
options.onInvalidations(paths);
|
|
165
|
+
if (queries.length > 0) {
|
|
166
|
+
options.onQueries?.(queries);
|
|
167
|
+
}
|
|
159
168
|
};
|
|
160
169
|
|
|
161
170
|
return {
|
|
162
171
|
catchUp() {
|
|
172
|
+
if (closed) {
|
|
173
|
+
return Promise.resolve();
|
|
174
|
+
}
|
|
163
175
|
requested = true;
|
|
164
176
|
if (!running) {
|
|
165
177
|
running = readUntilCurrent().finally(() => {
|
|
@@ -169,10 +181,14 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
169
181
|
return running;
|
|
170
182
|
},
|
|
171
183
|
cursor: () => currentCursor,
|
|
184
|
+
close() {
|
|
185
|
+
closed = true;
|
|
186
|
+
clearTimeout(pendingReset);
|
|
187
|
+
},
|
|
172
188
|
seed(cursor) {
|
|
173
189
|
currentCursor ??= cursor;
|
|
174
190
|
},
|
|
175
191
|
};
|
|
176
192
|
}
|
|
177
193
|
|
|
178
|
-
import { isAbortError } from "./abort.ts";
|
|
194
|
+
import { isAbortError } from "./router/abort.ts";
|