@teyik0/furin 0.6.0-alpha.1 → 0.7.0-alpha.2
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/dist/adapter/runtime-build.d.ts +1 -1
- package/dist/build/client.d.ts +4 -1
- package/dist/build/elysia-aot-worker.d.ts +22 -0
- package/dist/build/elysia-aot.d.ts +1 -1
- package/dist/build/entry-template.d.ts +3 -0
- package/dist/build/entry-template.ts +7 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +1880 -401
- package/dist/build/preload-manifest.d.ts +17 -0
- package/dist/build/types.d.ts +6 -0
- package/dist/cli/index.js +1878 -408
- package/dist/client/client-module.d.ts +26 -0
- package/dist/client/define-route.d.ts +9 -0
- package/dist/client/document.d.ts +2 -0
- package/dist/client/internal/runtime-types.d.ts +2 -0
- package/dist/client/link.js +942 -122
- package/dist/client/mutation.d.ts +38 -0
- package/dist/client/query-store.d.ts +85 -0
- package/dist/client/query.d.ts +14 -0
- package/dist/client/route-api.d.ts +11 -0
- package/dist/client/router/context.d.ts +3 -2
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +8 -1
- package/dist/client/router/navigation.d.ts +2 -9
- package/dist/client/router/optimistic.d.ts +41 -0
- package/dist/client/router/search/index.d.ts +3 -3
- package/dist/client/router/search-store.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +3 -0
- package/dist/client/router/types.d.ts +51 -7
- package/dist/client/sync.d.ts +39 -22
- package/dist/client.d.ts +11 -33
- package/dist/client.js +1219 -59
- package/dist/config.d.ts +7 -0
- package/dist/config.js +1 -0
- package/dist/define-route.d.ts +78 -32
- package/dist/env.d.ts +2 -2
- package/dist/furin.d.ts +1 -2
- package/dist/furin.js +2484 -708
- package/dist/plugin/hmr-dependencies.d.ts +2 -0
- package/dist/plugin/index.js +349 -18
- package/dist/plugin/transform-client-module.d.ts +16 -0
- package/dist/plugin/transform-client.d.ts +2 -0
- package/dist/plugin/transform-isomorphic.d.ts +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/rsc-client.js +87 -16
- package/dist/rsc.js +87 -16
- package/dist/server/auto-invalidate/registry.d.ts +1 -0
- package/dist/server/auto-invalidate/types.d.ts +2 -0
- package/dist/server/cache/isr.d.ts +2 -4
- package/dist/server/cache/route-cache.d.ts +5 -0
- package/dist/server/dev/graph.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +5 -19
- package/dist/server/internal.d.ts +3 -0
- package/dist/server/internal.js +55 -35
- package/dist/server/production-server.js +54 -34
- package/dist/server/render/loaders.d.ts +4 -2
- package/dist/server/render/react-stream.d.ts +3 -0
- package/dist/server/render/ssr.d.ts +2 -1
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +2 -0
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/patterns.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -1
- package/dist/server/sync/adapter.d.ts +25 -4
- package/dist/server/sync/atomic.d.ts +25 -0
- package/dist/server/sync/drizzle/index.d.ts +45 -0
- package/dist/server/sync/drizzle/index.js +540 -0
- package/dist/server/sync/execution-error.d.ts +2 -0
- package/dist/server/sync/index.d.ts +2 -1
- package/dist/server/sync/index.js +533 -105
- package/dist/server/sync/mutation-handler.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +34 -11
- package/dist/server/sync/postgres/execute.d.ts +3 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +34 -13
- package/dist/server/sync/postgres/sql.d.ts +8 -0
- package/dist/server/sync/prisma/index.d.ts +24 -0
- package/dist/server/sync/prisma/index.js +340 -0
- package/dist/server/sync/queries.d.ts +21 -0
- package/dist/server/sync/query-context.d.ts +5 -0
- package/dist/server/sync/redis/index.js +3 -3
- package/dist/server/sync/redis/scripts.d.ts +1 -1
- package/dist/server/sync/response.d.ts +1 -0
- package/dist/server/sync/sqlite/index.d.ts +3 -0
- package/dist/server/sync/sqlite/index.js +10 -4
- package/dist/server/sync/stream.d.ts +2 -5
- package/dist/server/sync/validation.d.ts +4 -0
- package/dist/shared/defer.d.ts +31 -0
- package/dist/shared/error.d.ts +2 -2
- package/dist/shared/page-key.d.ts +7 -0
- package/dist/shared/query-bindings.d.ts +12 -0
- package/dist/shared/route-frame.d.ts +1 -0
- package/dist/shared/sync-query.d.ts +40 -0
- package/package.json +29 -6
- package/src/adapter/package.ts +12 -2
- package/src/adapter/runtime-build.ts +63 -12
- package/src/adapter/static.ts +7 -2
- package/src/adapter/vercel.ts +15 -13
- package/src/build/client.ts +23 -5
- package/src/build/elysia-aot-worker.ts +51 -0
- package/src/build/elysia-aot.ts +83 -19
- package/src/build/entry-template.ts +7 -0
- package/src/build/hydrate.ts +21 -3
- package/src/build/preload-manifest.ts +100 -0
- package/src/build/production-instrumentation.ts +6 -3
- package/src/build/types.ts +4 -0
- package/src/cli/index.ts +1 -0
- package/src/client/browser-events-runtime.ts +4 -0
- package/src/client/client-module.ts +57 -0
- package/src/client/define-route.ts +11 -1
- package/src/client/document.tsx +28 -18
- package/src/client/hmr.ts +2 -1
- package/src/client/internal/runtime-types.ts +2 -0
- package/src/client/link.tsx +8 -8
- package/src/client/mutation.ts +136 -0
- package/src/client/query-store.ts +418 -0
- package/src/client/query.tsx +67 -0
- package/src/client/route-api.tsx +75 -0
- package/src/client/router/boundary-tree.tsx +19 -12
- package/src/client/router/context.ts +57 -4
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +29 -1
- package/src/client/router/navigation.ts +3 -50
- package/src/client/router/optimistic.ts +233 -0
- package/src/client/router/provider.tsx +306 -46
- package/src/client/router/search/index.ts +37 -17
- package/src/client/router/search-store.ts +4 -0
- package/src/client/router/sync-catch-up.ts +7 -0
- package/src/client/router/types.ts +73 -9
- package/src/client/sync.ts +438 -65
- package/src/client.ts +20 -60
- package/src/config.ts +5 -0
- package/src/define-route.ts +113 -55
- package/src/env.d.ts +2 -2
- package/src/furin.ts +75 -13
- package/src/plugin/hmr-dependencies.ts +58 -0
- package/src/plugin/index.ts +38 -2
- package/src/plugin/routes.ts +28 -16
- package/src/plugin/transform-client-module.ts +123 -0
- package/src/plugin/transform-client.ts +293 -13
- package/src/plugin/transform-isomorphic.ts +11 -5
- package/src/routes.ts +8 -0
- package/src/rsc/shared.tsx +104 -18
- package/src/server/auto-invalidate/registry.ts +4 -0
- package/src/server/auto-invalidate/runtime.ts +17 -0
- package/src/server/auto-invalidate/types.ts +6 -0
- package/src/server/cache/isr.ts +6 -34
- package/src/server/cache/route-cache.ts +40 -4
- package/src/server/dev/graph.ts +16 -2
- package/src/server/dev-page-plugin.ts +93 -59
- package/src/server/internal.ts +3 -0
- package/src/server/render/document.tsx +10 -1
- package/src/server/render/element.tsx +21 -11
- package/src/server/render/isr.ts +61 -29
- package/src/server/render/loaders.ts +118 -47
- package/src/server/render/mixed-cache.ts +33 -4
- package/src/server/render/not-found.ts +4 -7
- package/src/server/render/ppr-document.ts +2 -1
- package/src/server/render/ppr-route.ts +30 -10
- package/src/server/render/react-stream.ts +17 -0
- package/src/server/render/route-frame-transport.ts +3 -0
- package/src/server/render/ssg.ts +51 -18
- package/src/server/render/ssr.ts +53 -8
- package/src/server/render/template.ts +23 -0
- package/src/server/router/defined-route.ts +3 -0
- package/src/server/router/discovery.ts +25 -9
- package/src/server/router/hmr.ts +3 -2
- package/src/server/router/patterns.ts +16 -0
- package/src/server/router/plugin.ts +27 -12
- package/src/server/router/types.ts +1 -1
- package/src/server/sync/adapter.ts +41 -4
- package/src/server/sync/atomic.ts +303 -0
- package/src/server/sync/drizzle/index.ts +145 -0
- package/src/server/sync/execution-error.ts +1 -0
- package/src/server/sync/fingerprint.ts +2 -6
- package/src/server/sync/index.ts +6 -0
- package/src/server/sync/mutation-handler.ts +69 -0
- package/src/server/sync/plugin.ts +177 -60
- package/src/server/sync/postgres/execute.ts +20 -0
- package/src/server/sync/postgres/index.ts +52 -16
- package/src/server/sync/postgres/sql.ts +20 -0
- package/src/server/sync/prisma/index.ts +70 -0
- package/src/server/sync/queries.ts +75 -0
- package/src/server/sync/query-context.ts +85 -0
- package/src/server/sync/redis/index.ts +7 -3
- package/src/server/sync/redis/scripts.ts +1 -1
- package/src/server/sync/response.ts +21 -0
- package/src/server/sync/sqlite/index.ts +19 -8
- package/src/server/sync/stream.ts +14 -22
- package/src/server/sync/validation.ts +34 -0
- package/src/shared/defer.ts +48 -0
- package/src/shared/error.ts +2 -2
- package/src/shared/page-key.ts +36 -0
- package/src/shared/query-bindings.ts +138 -0
- package/src/shared/route-frame.ts +13 -1
- package/src/shared/route-map.ts +12 -2
- package/src/shared/sync-query.ts +138 -0
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RouteSearch, RouteTo } from "@teyik0/furin/link";
|
|
2
2
|
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
3
3
|
import {
|
|
4
4
|
findSearchDefaultsForRouteTarget,
|
|
5
5
|
type SearchParamsInput,
|
|
6
6
|
} from "../../../shared/search-params.ts";
|
|
7
7
|
import { buildHref } from "../link-utils.ts";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
FALLBACK_SEARCH_STORE,
|
|
10
|
+
type SearchStore,
|
|
11
|
+
SearchStoreContext,
|
|
12
|
+
type SearchStoreSnapshot,
|
|
13
|
+
} from "../search-store.ts";
|
|
9
14
|
|
|
10
|
-
export type SearchRouteTo =
|
|
11
|
-
? RouteTo
|
|
12
|
-
: (string & {}) | keyof RouteManifest;
|
|
15
|
+
export type SearchRouteTo = RouteTo;
|
|
13
16
|
|
|
14
|
-
type SearchRouteSearch<To extends SearchRouteTo> = RouteSearch<To
|
|
17
|
+
type SearchRouteSearch<To extends SearchRouteTo> = RouteSearch<To>;
|
|
15
18
|
|
|
16
19
|
export type EmptyRouteSearch = Record<PropertyKey, never>;
|
|
17
20
|
|
|
@@ -38,19 +41,31 @@ function pathnameFromLogicalHref(logicalHref: string): string {
|
|
|
38
41
|
return new URL(logicalHref, "http://furin.local").pathname;
|
|
39
42
|
}
|
|
40
43
|
|
|
44
|
+
function assertSearchRoute(from: string, snapshot: SearchStoreSnapshot, store: SearchStore): void {
|
|
45
|
+
if (
|
|
46
|
+
(snapshot.currentPattern === undefined && store !== FALLBACK_SEARCH_STORE) ||
|
|
47
|
+
(from !== snapshot.currentPattern && from !== pathnameFromLogicalHref(snapshot.currentHref))
|
|
48
|
+
) {
|
|
49
|
+
throw new Error(`[furin] useSearch("${from}") does not match the current route.`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
function useSearchSelection<To extends SearchRouteTo, TSelected>(
|
|
54
|
+
from: To,
|
|
42
55
|
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
43
56
|
): TSelected {
|
|
44
57
|
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
45
58
|
|
|
46
|
-
const getSnapshot = useCallback(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
const getSnapshot = useCallback(() => {
|
|
60
|
+
const snapshot = store.getSnapshot();
|
|
61
|
+
assertSearchRoute(from, snapshot, store);
|
|
62
|
+
return selector(snapshot.search as ResolvedRouteSearch<To>);
|
|
63
|
+
}, [from, selector, store]);
|
|
64
|
+
const getServerSnapshot = useCallback(() => {
|
|
65
|
+
const snapshot = store.getServerSnapshot();
|
|
66
|
+
assertSearchRoute(from, snapshot, store);
|
|
67
|
+
return selector(snapshot.search as ResolvedRouteSearch<To>);
|
|
68
|
+
}, [from, selector, store]);
|
|
54
69
|
|
|
55
70
|
return useSyncExternalStore(store.subscribe, getSnapshot, getServerSnapshot);
|
|
56
71
|
}
|
|
@@ -63,17 +78,22 @@ export function useSearch<To extends SearchRouteTo, TSelected>(
|
|
|
63
78
|
selector: (search: ResolvedRouteSearch<To>) => TSelected
|
|
64
79
|
): [TSelected, SetSearch<To>];
|
|
65
80
|
export function useSearch<To extends SearchRouteTo, TSelected>(
|
|
66
|
-
|
|
81
|
+
from: To,
|
|
67
82
|
selector?: (search: ResolvedRouteSearch<To>) => TSelected
|
|
68
83
|
): [ResolvedRouteSearch<To> | TSelected, SetSearch<To>] {
|
|
69
84
|
const store = useContext(SearchStoreContext) ?? FALLBACK_SEARCH_STORE;
|
|
70
|
-
const selected = useSearchSelection<To, ResolvedRouteSearch<To> | TSelected>((search) =>
|
|
85
|
+
const selected = useSearchSelection<To, ResolvedRouteSearch<To> | TSelected>(from, (search) =>
|
|
71
86
|
selector ? selector(search) : search
|
|
72
87
|
);
|
|
73
88
|
|
|
74
89
|
const setSearch = useCallback<SetSearch<To>>(
|
|
75
90
|
(next, opts) => {
|
|
76
91
|
const snapshot = store.getSnapshot();
|
|
92
|
+
try {
|
|
93
|
+
assertSearchRoute(from, snapshot, store);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return Promise.reject(error);
|
|
96
|
+
}
|
|
77
97
|
const search = snapshot.search as ResolvedRouteSearch<To>;
|
|
78
98
|
const patch = typeof next === "function" ? next(search) : next;
|
|
79
99
|
const merged = { ...search, ...patch } as SearchParamsInput;
|
|
@@ -82,7 +102,7 @@ export function useSearch<To extends SearchRouteTo, TSelected>(
|
|
|
82
102
|
const href = buildHref(pathname, merged, undefined, searchDefaults);
|
|
83
103
|
return snapshot.navigate(href, opts);
|
|
84
104
|
},
|
|
85
|
-
[store]
|
|
105
|
+
[from, store]
|
|
86
106
|
);
|
|
87
107
|
|
|
88
108
|
return [selected, setSearch];
|
|
@@ -5,6 +5,7 @@ import type { RouterContextValue } from "./types.ts";
|
|
|
5
5
|
|
|
6
6
|
export interface SearchStoreSnapshot {
|
|
7
7
|
currentHref: string;
|
|
8
|
+
currentPattern: string | undefined;
|
|
8
9
|
navigate: RouterContextValue["navigate"];
|
|
9
10
|
search: SearchParamsInput;
|
|
10
11
|
searchRoutes: SearchRouteMetadata[];
|
|
@@ -23,6 +24,7 @@ export interface SearchStore {
|
|
|
23
24
|
function searchSnapshotChanged(a: SearchStoreSnapshot, b: SearchStoreSnapshot): boolean {
|
|
24
25
|
return (
|
|
25
26
|
a.currentHref !== b.currentHref ||
|
|
27
|
+
a.currentPattern !== b.currentPattern ||
|
|
26
28
|
a.navigate !== b.navigate ||
|
|
27
29
|
a.search !== b.search ||
|
|
28
30
|
a.searchRoutes !== b.searchRoutes
|
|
@@ -66,6 +68,7 @@ export function createSearchStore(initialSnapshot: SearchStoreSnapshot): SearchS
|
|
|
66
68
|
export function searchSnapshotFromRouterContext(context: RouterContextValue): SearchStoreSnapshot {
|
|
67
69
|
return {
|
|
68
70
|
currentHref: context.currentHref,
|
|
71
|
+
currentPattern: context.currentPattern,
|
|
69
72
|
navigate: context.navigate,
|
|
70
73
|
search: context.search,
|
|
71
74
|
searchRoutes: context.searchRoutes,
|
|
@@ -74,6 +77,7 @@ export function searchSnapshotFromRouterContext(context: RouterContextValue): Se
|
|
|
74
77
|
|
|
75
78
|
export const FALLBACK_SEARCH_STORE = createSearchStore({
|
|
76
79
|
currentHref: "/",
|
|
80
|
+
currentPattern: undefined,
|
|
77
81
|
navigate: (href, _opts) => {
|
|
78
82
|
if (typeof window !== "undefined") {
|
|
79
83
|
if (navigationHrefPolicy(href, window.location.origin) === "blocked") {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export interface SyncChangePayload {
|
|
3
3
|
cursor: string;
|
|
4
4
|
invalidations: readonly string[];
|
|
5
|
+
queries?: readonly import("../../shared/sync-query.ts").QueryIdentity[];
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export interface SyncChangePagePayload {
|
|
@@ -14,6 +15,8 @@ export interface SyncChangePagePayload {
|
|
|
14
15
|
interface SyncCatchUpOptions {
|
|
15
16
|
fetchPage: (after: string | undefined) => Promise<SyncChangePagePayload>;
|
|
16
17
|
onInvalidations: (invalidations: readonly string[]) => void;
|
|
18
|
+
onQueries?: (identities: readonly import("../../shared/sync-query.ts").QueryIdentity[]) => void;
|
|
19
|
+
onReset?: () => void;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export interface SyncCatchUp {
|
|
@@ -81,12 +84,16 @@ export function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp {
|
|
|
81
84
|
do {
|
|
82
85
|
page = await options.fetchPage(currentCursor ?? "0");
|
|
83
86
|
if (page.reset) {
|
|
87
|
+
options.onReset?.();
|
|
84
88
|
options.onInvalidations(["/:layout"]);
|
|
85
89
|
currentCursor = page.cursor;
|
|
86
90
|
break;
|
|
87
91
|
}
|
|
88
92
|
for (const change of page.changes) {
|
|
89
93
|
options.onInvalidations(change.invalidations);
|
|
94
|
+
if (change.queries) {
|
|
95
|
+
options.onQueries?.(change.queries);
|
|
96
|
+
}
|
|
90
97
|
}
|
|
91
98
|
currentCursor = page.cursor;
|
|
92
99
|
} while (page.hasMore);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteMap } from "@teyik0/furin/routes";
|
|
1
|
+
import type { RouteMap, RoutePatternMap } from "@teyik0/furin/routes";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import type { HeadOptions } from "../../client.ts";
|
|
4
4
|
import type {
|
|
@@ -15,6 +15,12 @@ import type { FurinServerErrorPayload } from "../server-error.ts";
|
|
|
15
15
|
/** Exact public projection of the generated Elysia route map. */
|
|
16
16
|
export type RouteManifest = RouteMap;
|
|
17
17
|
|
|
18
|
+
type RouteOf<To extends RouteTo> = To extends keyof RoutePatternMap
|
|
19
|
+
? RoutePatternMap[To]
|
|
20
|
+
: To extends keyof RouteManifest
|
|
21
|
+
? RouteManifest[To]
|
|
22
|
+
: never;
|
|
23
|
+
|
|
18
24
|
type RouteSearchInput<Route> = Route extends { elysia: infer App }
|
|
19
25
|
? unknown extends ElysiaRouteQuery<ElysiaRouteLeaf<App>>
|
|
20
26
|
? undefined
|
|
@@ -24,13 +30,13 @@ type RouteSearchInput<Route> = Route extends { elysia: infer App }
|
|
|
24
30
|
type RouteParamInput<Value> = Value extends number ? string | number : Value;
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
|
-
*
|
|
33
|
+
* Literal route patterns for `to` completion, with a string fallback for concrete URLs.
|
|
28
34
|
* Falls back to `string` when furin-env.d.ts has not been generated yet.
|
|
29
|
-
*
|
|
35
|
+
* The string fallback also accepts concrete paths and external URLs.
|
|
30
36
|
*/
|
|
31
37
|
export type RouteTo = keyof RouteManifest extends never
|
|
32
38
|
? string
|
|
33
|
-
:
|
|
39
|
+
: keyof RoutePatternMap | (string & {});
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
42
|
* The typed search params for a given `to` pathname.
|
|
@@ -38,8 +44,8 @@ export type RouteTo = keyof RouteManifest extends never
|
|
|
38
44
|
*/
|
|
39
45
|
export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never
|
|
40
46
|
? SearchParamsInput
|
|
41
|
-
: To extends keyof RouteManifest
|
|
42
|
-
? RouteSearchInput<
|
|
47
|
+
: To extends keyof RouteManifest | keyof RoutePatternMap
|
|
48
|
+
? RouteSearchInput<RouteOf<To>>
|
|
43
49
|
: undefined;
|
|
44
50
|
|
|
45
51
|
/**
|
|
@@ -49,8 +55,8 @@ export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never
|
|
|
49
55
|
*/
|
|
50
56
|
export type RouteParamsOf<To extends RouteTo> = keyof RouteManifest extends never
|
|
51
57
|
? Record<string, string | number>
|
|
52
|
-
: To extends keyof RouteManifest
|
|
53
|
-
?
|
|
58
|
+
: To extends keyof RouteManifest | keyof RoutePatternMap
|
|
59
|
+
? RouteOf<To> extends { elysia: infer App }
|
|
54
60
|
? unknown extends ElysiaRouteParams<ElysiaRouteLeaf<App>>
|
|
55
61
|
? undefined
|
|
56
62
|
: keyof ElysiaRouteParams<ElysiaRouteLeaf<App>> extends never
|
|
@@ -65,7 +71,26 @@ export type RouteParamsOf<To extends RouteTo> = keyof RouteManifest extends neve
|
|
|
65
71
|
|
|
66
72
|
export type PreloadStrategy = false | "intent" | "viewport" | "render";
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
type LinkPathParamKeys<Path extends string> = Path extends `${infer Segment}/${infer Rest}`
|
|
75
|
+
? LinkPathParamKeys<Segment> | LinkPathParamKeys<Rest>
|
|
76
|
+
: Path extends `:${infer Key}`
|
|
77
|
+
? Key
|
|
78
|
+
: Path extends "*"
|
|
79
|
+
? "*"
|
|
80
|
+
: never;
|
|
81
|
+
|
|
82
|
+
type LinkParams<To extends RouteTo> = [To] extends [keyof RoutePatternMap]
|
|
83
|
+
? LinkPathParamKeys<To> extends never
|
|
84
|
+
? { params?: RouteParamsOf<To> }
|
|
85
|
+
: {
|
|
86
|
+
params: RouteParamsOf<To> &
|
|
87
|
+
Required<
|
|
88
|
+
Pick<RouteParamsOf<To>, Extract<LinkPathParamKeys<To>, keyof RouteParamsOf<To>>>
|
|
89
|
+
>;
|
|
90
|
+
}
|
|
91
|
+
: { params?: RouteParamsOf<To> };
|
|
92
|
+
|
|
93
|
+
export interface LinkBaseProps<To extends RouteTo>
|
|
69
94
|
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "children"> {
|
|
70
95
|
/**
|
|
71
96
|
* Extra props merged onto the anchor when the link is active.
|
|
@@ -110,6 +135,39 @@ export interface LinkProps<To extends RouteTo = RouteTo>
|
|
|
110
135
|
to: To;
|
|
111
136
|
}
|
|
112
137
|
|
|
138
|
+
export type LinkProps<To extends RouteTo = RouteTo> = LinkBaseProps<To> & LinkParams<To>;
|
|
139
|
+
|
|
140
|
+
export type NavigationTo = keyof RouteManifest | keyof RoutePatternMap extends never
|
|
141
|
+
? string
|
|
142
|
+
: keyof RoutePatternMap | keyof RouteManifest | `https://${string}` | `http://${string}`;
|
|
143
|
+
|
|
144
|
+
export type RouteTarget<To extends NavigationTo> = To extends NavigationTo
|
|
145
|
+
? { to: To; hash?: string; search?: RouteSearch<NoInfer<To>> } & LinkParams<NoInfer<To>>
|
|
146
|
+
: never;
|
|
147
|
+
|
|
148
|
+
export interface NavigationOptions {
|
|
149
|
+
replace?: boolean;
|
|
150
|
+
resetScroll?: boolean;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type NavigateInput<To extends NavigationTo> = RouteTarget<To> & NavigationOptions;
|
|
154
|
+
export type Navigate = <To extends NavigationTo>(next: NavigateInput<To>) => Promise<void>;
|
|
155
|
+
|
|
156
|
+
export interface RouterNavigate {
|
|
157
|
+
(href: string, opts?: NavigationOptions): Promise<void>;
|
|
158
|
+
<To extends NavigationTo>(next: NavigateInput<To>): Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface Prefetch {
|
|
162
|
+
(href: string, opts?: { staleTime?: number }): void;
|
|
163
|
+
<To extends NavigationTo>(next: RouteTarget<To> & { staleTime?: number }): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type Router = Omit<RouterContextValue, "navigate" | "prefetch"> & {
|
|
167
|
+
navigate: RouterNavigate;
|
|
168
|
+
prefetch: Prefetch;
|
|
169
|
+
};
|
|
170
|
+
|
|
113
171
|
export interface RouterContextValue {
|
|
114
172
|
/**
|
|
115
173
|
* Sub-path prefix for static deployments (e.g. "/furin").
|
|
@@ -119,6 +177,8 @@ export interface RouterContextValue {
|
|
|
119
177
|
basePath: string;
|
|
120
178
|
/** Current **logical** pathname + search (basePath stripped). Used by Link for active-state detection. */
|
|
121
179
|
currentHref: string;
|
|
180
|
+
/** Pattern of the currently rendered route, when a page route is matched. */
|
|
181
|
+
currentPattern?: string;
|
|
122
182
|
defaultPreload: PreloadStrategy;
|
|
123
183
|
defaultPreloadDelay: number;
|
|
124
184
|
defaultPreloadStaleTime: number;
|
|
@@ -156,6 +216,8 @@ export interface RouterContextValue {
|
|
|
156
216
|
export interface ClientSegmentBoundary {
|
|
157
217
|
depth: number;
|
|
158
218
|
error?: ErrorComponent;
|
|
219
|
+
/** False when a pathless directory shares index 0 but does not own the root fallback. */
|
|
220
|
+
isRoot?: boolean;
|
|
159
221
|
notFound?: NotFoundComponent;
|
|
160
222
|
}
|
|
161
223
|
|
|
@@ -245,6 +307,7 @@ export interface RouterState {
|
|
|
245
307
|
/** The canonical href after server-side redirects (e.g. query-default redirect). */
|
|
246
308
|
finalHref?: string;
|
|
247
309
|
head?: HeadOptions;
|
|
310
|
+
hydrateQueries?: ReturnType<import("../query-store.ts").QueryStore["captureHydration"]>;
|
|
248
311
|
/**
|
|
249
312
|
* The currently rendered route.
|
|
250
313
|
*
|
|
@@ -259,6 +322,7 @@ export interface RouterState {
|
|
|
259
322
|
* Explicit boundary chain to use for the not-found render.
|
|
260
323
|
*/
|
|
261
324
|
notFoundBoundaries?: ClientSegmentBoundary[] | undefined;
|
|
325
|
+
querySeeds?: import("../../shared/sync-query.ts").QuerySeed[];
|
|
262
326
|
title?: string;
|
|
263
327
|
}
|
|
264
328
|
|