@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.4

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.
Files changed (134) hide show
  1. package/README.md +4 -0
  2. package/dist/adapter/bun.d.ts +3 -0
  3. package/dist/adapter/static.d.ts +3 -0
  4. package/dist/build/client.d.ts +25 -0
  5. package/dist/build/compile-entry.d.ts +9 -0
  6. package/dist/build/compile-entry.ts +109 -0
  7. package/dist/build/entry-template.d.ts +38 -0
  8. package/dist/build/entry-template.ts +156 -0
  9. package/dist/build/hydrate.d.ts +24 -0
  10. package/dist/build/index.d.ts +8 -0
  11. package/dist/build/index.js +8106 -0
  12. package/dist/build/route-types.d.ts +23 -0
  13. package/dist/build/scan-server.d.ts +8 -0
  14. package/dist/build/server-routes-entry.d.ts +13 -0
  15. package/dist/build/server-routes-entry.ts +36 -0
  16. package/dist/build/shared.d.ts +12 -0
  17. package/dist/build/ssg-cache.d.ts +4 -0
  18. package/dist/build/types.d.ts +80 -0
  19. package/dist/cli/config.d.ts +9 -0
  20. package/dist/cli/index.d.ts +2 -0
  21. package/dist/cli/index.js +8097 -0
  22. package/dist/client/boundaries.d.ts +117 -0
  23. package/dist/client/default-screens.d.ts +17 -0
  24. package/dist/client/link.d.ts +22 -0
  25. package/dist/client/link.js +4391 -0
  26. package/dist/client/router/abort.d.ts +1 -0
  27. package/dist/client/router/boundary-tree.d.ts +26 -0
  28. package/dist/client/router/context.d.ts +8 -0
  29. package/dist/client/router/history.d.ts +9 -0
  30. package/dist/client/router/index.d.ts +11 -0
  31. package/dist/client/router/link-utils.d.ts +53 -0
  32. package/dist/client/router/navigation.d.ts +10 -0
  33. package/dist/client/router/provider.d.ts +4 -0
  34. package/dist/client/router/search/index.d.ts +18 -0
  35. package/dist/client/router/search-store.d.ts +21 -0
  36. package/dist/client/router/spa-response.d.ts +58 -0
  37. package/dist/client/router/sync-catch-up.d.ts +29 -0
  38. package/dist/client/router/types.d.ts +292 -0
  39. package/dist/client/server-error.d.ts +12 -0
  40. package/dist/client/sync.d.ts +25 -0
  41. package/dist/client.d.ts +243 -0
  42. package/dist/client.js +140 -0
  43. package/dist/config.d.ts +57 -0
  44. package/dist/config.js +29 -0
  45. package/dist/env.d.ts +50 -0
  46. package/dist/furin.d.ts +77 -0
  47. package/dist/furin.js +8977 -0
  48. package/dist/plugin/index.d.ts +20 -0
  49. package/dist/plugin/index.js +1500 -0
  50. package/dist/plugin/transform-client.d.ts +10 -0
  51. package/dist/server/auto-invalidate/index.d.ts +4 -0
  52. package/dist/server/auto-invalidate/plugin.d.ts +38 -0
  53. package/dist/server/auto-invalidate/registry.d.ts +9 -0
  54. package/dist/server/auto-invalidate/runtime.d.ts +9 -0
  55. package/dist/server/auto-invalidate/types.d.ts +12 -0
  56. package/dist/server/cache/dev-loader.d.ts +28 -0
  57. package/dist/server/cache/index.d.ts +10 -0
  58. package/dist/server/cache/invalidation.d.ts +12 -0
  59. package/dist/server/cache/isr-ssg.d.ts +26 -0
  60. package/dist/server/cache/isr.d.ts +6 -0
  61. package/dist/server/cache/registry.d.ts +5 -0
  62. package/dist/server/cache/route-cache.d.ts +26 -0
  63. package/dist/server/cache/ssg.d.ts +5 -0
  64. package/dist/server/context-logger.d.ts +28 -0
  65. package/dist/server/dev-inspector.d.ts +89 -0
  66. package/dist/server/dev-page-plugin.d.ts +112 -0
  67. package/dist/server/internal.d.ts +35 -0
  68. package/dist/server/internal.js +17 -0
  69. package/dist/server/lang-detect.d.ts +5 -0
  70. package/dist/server/render/assemble.d.ts +49 -0
  71. package/dist/server/render/element.d.ts +24 -0
  72. package/dist/server/render/index.d.ts +7 -0
  73. package/dist/server/render/index.ts +22 -0
  74. package/dist/server/render/isr.d.ts +4 -0
  75. package/dist/server/render/loaders.d.ts +64 -0
  76. package/dist/server/render/not-found.d.ts +6 -0
  77. package/dist/server/render/shell.d.ts +39 -0
  78. package/dist/server/render/shell.ts +202 -0
  79. package/dist/server/render/ssg.d.ts +9 -0
  80. package/dist/server/render/ssr.d.ts +108 -0
  81. package/dist/server/render/template.d.ts +6 -0
  82. package/dist/server/router/discovery.d.ts +16 -0
  83. package/dist/server/router/hmr.d.ts +65 -0
  84. package/dist/server/router/index.d.ts +6 -0
  85. package/dist/server/router/index.js +27 -0
  86. package/dist/server/router/index.ts +28 -0
  87. package/dist/server/router/patterns.d.ts +40 -0
  88. package/dist/server/router/plugin.d.ts +21 -0
  89. package/dist/server/router/schemas.d.ts +59 -0
  90. package/dist/server/router/types.d.ts +60 -0
  91. package/dist/server/runtime-env.d.ts +3 -0
  92. package/dist/server/runtime-env.js +10 -0
  93. package/dist/server/sync/adapter.d.ts +62 -0
  94. package/dist/server/sync/config.d.ts +6 -0
  95. package/dist/server/sync/fingerprint.d.ts +6 -0
  96. package/dist/server/sync/index.d.ts +4 -0
  97. package/dist/server/sync/memory-adapter.d.ts +17 -0
  98. package/dist/server/sync/plugin.d.ts +186 -0
  99. package/dist/server/sync/response.d.ts +4 -0
  100. package/dist/server/sync/stream.d.ts +59 -0
  101. package/dist/shared/await.d.ts +67 -0
  102. package/dist/shared/deferred-ndjson.d.ts +32 -0
  103. package/dist/shared/digest.d.ts +16 -0
  104. package/dist/shared/error.d.ts +37 -0
  105. package/dist/shared/not-found.d.ts +19 -0
  106. package/dist/shared/search-params.d.ts +17 -0
  107. package/dist/shared/utils/ast-walk.d.ts +18 -0
  108. package/dist/shared/utils/index.d.ts +13 -0
  109. package/package.json +5 -5
  110. package/src/build/hydrate.ts +4 -1
  111. package/src/build/shared.ts +4 -3
  112. package/src/client/router/abort.ts +5 -0
  113. package/src/client/router/link-utils.ts +8 -1
  114. package/src/client/router/provider.tsx +130 -6
  115. package/src/client/router/sync-catch-up.ts +113 -0
  116. package/src/client/router/types.ts +5 -0
  117. package/src/client/sync.ts +98 -0
  118. package/src/client.ts +15 -1
  119. package/src/furin.ts +25 -4
  120. package/src/server/auto-invalidate/runtime.ts +3 -2
  121. package/src/server/dev-page-plugin.ts +15 -10
  122. package/src/server/render/assemble.ts +30 -3
  123. package/src/server/render/isr.ts +8 -2
  124. package/src/server/render/ssr.ts +9 -1
  125. package/src/server/router/plugin.ts +2 -2
  126. package/src/server/sync/adapter.ts +65 -0
  127. package/src/server/sync/config.ts +29 -0
  128. package/src/server/sync/fingerprint.ts +44 -0
  129. package/src/server/sync/index.ts +15 -0
  130. package/src/server/sync/memory-adapter.ts +196 -0
  131. package/src/server/sync/plugin.ts +200 -0
  132. package/src/server/sync/response.ts +77 -0
  133. package/src/server/sync/stream.ts +152 -0
  134. package/src/shared/deferred-ndjson.ts +7 -0
@@ -0,0 +1 @@
1
+ export declare function isAbortError(error: unknown): boolean;
@@ -0,0 +1,26 @@
1
+ import type React from "react";
2
+ import type { RuntimeRoute } from "../../client.ts";
3
+ import { type BoundaryOptions } from "../boundaries.tsx";
4
+ import type { LoadedClientRoute, RootBoundaryOptions, RouterContextValue } from "./types.ts";
5
+ /**
6
+ * Composes the outermost tree produced by `RouterProvider`:
7
+ *
8
+ * <RouterContext.Provider value={context}>
9
+ * <FurinErrorBoundary digest onReset resetKey>
10
+ * {pageElement}
11
+ * </FurinErrorBoundary>
12
+ * </RouterContext.Provider>
13
+ *
14
+ * `RouterContext.Provider` is the OUTERMOST element so that a root-level
15
+ * `error.tsx` rendered by the boundary can still call `useRouter()` / render
16
+ * `<Link>` (the context is in scope above the boundary).
17
+ *
18
+ * @internal Exported for unit testing only.
19
+ */
20
+ export declare function buildRouterTree(context: RouterContextValue, pageElement: React.ReactNode, options: RootBoundaryOptions): React.ReactElement;
21
+ /** @internal Exported for unit testing only. */
22
+ export declare function buildPageElement(match: LoadedClientRoute, root: RuntimeRoute | null, data: Record<string, unknown>, options: BoundaryOptions | undefined, error: {
23
+ digest: string;
24
+ message: string;
25
+ status: number;
26
+ } | undefined): React.ReactNode;
@@ -0,0 +1,8 @@
1
+ import type { RouterContextValue } from "./types.ts";
2
+ export declare const RouterContext: import("react").Context<RouterContextValue | null>;
3
+ export declare const CLIENT_FALLBACK_ROUTER: RouterContextValue;
4
+ /**
5
+ * Returns the current router context.
6
+ * Provides a graceful fallback (full-page navigation) when used outside RouterProvider.
7
+ */
8
+ export declare function useRouter(): RouterContextValue;
@@ -0,0 +1,9 @@
1
+ export declare const SCROLL_STORAGE_KEY = "__furin_scroll__";
2
+ export declare function getHistoryKey(state: unknown): string | undefined;
3
+ export declare function generateHistoryKey(): string;
4
+ export declare function saveScrollPosition(key: string): void;
5
+ /**
6
+ * Returns `true` when the server reports a different build-id from the one
7
+ * embedded in the initial HTML (`<meta name="furin-build-id">`).
8
+ */
9
+ export declare function isStaleDeployResponse(res: Response): boolean;
@@ -0,0 +1,11 @@
1
+ export { buildPageElement, buildRouterTree } from "./boundary-tree.tsx";
2
+ export { CLIENT_FALLBACK_ROUTER, RouterContext, useRouter } from "./context.ts";
3
+ export { generateHistoryKey, getHistoryKey, isStaleDeployResponse, SCROLL_STORAGE_KEY, saveScrollPosition, } from "./history.ts";
4
+ export { applyRevalidateHeader, buildHref, normalizeHref, normalizePath, shouldAutoRefreshPath, shouldInterceptClick, shouldRefetch, stripHashFromHref, TRAILING_SLASHES_RE, toLogical, } from "./link-utils.ts";
5
+ export type { Navigate, NavigateInput } from "./navigation.ts";
6
+ export { useNavigate } from "./navigation.ts";
7
+ export { RouterProvider } from "./provider.tsx";
8
+ export type { SearchStore, SearchStoreSnapshot } from "./search-store.ts";
9
+ export { createSearchStore, FALLBACK_SEARCH_STORE, SearchStoreContext, searchSnapshotFromRouterContext, } from "./search-store.ts";
10
+ export { buildDataEndpoint, buildNotFoundPageElement, classifySpaResponse, detectStaticMode, parsePageResponse, pickDeepestNotFound, } from "./spa-response.ts";
11
+ export type { CacheEntry, ClientRoute, ClientSegmentBoundary, LinkProps, LoadedClientRoute, PreloadStrategy, RootBoundaryOptions, RouteManifest, RouterContextValue, RouterProviderProps, RouterState, RouteSearch, RouteTo, SpaResponseKind, } from "./types.ts";
@@ -0,0 +1,53 @@
1
+ import { type SearchParamsInput } from "../../shared/search-params.ts";
2
+ import type { CacheEntry } from "./types.ts";
3
+ /** Strips one or more trailing slashes — used by `buildDataEndpoint` in static mode. */
4
+ export declare const TRAILING_SLASHES_RE: RegExp;
5
+ /**
6
+ * Builds a full href string from a pathname, optional search params, and optional hash.
7
+ * Null/undefined search values are omitted.
8
+ *
9
+ * @internal Exported for unit testing only.
10
+ */
11
+ export declare function buildHref(to: string, search: SearchParamsInput | null | undefined, hash: string | undefined, searchDefaults?: SearchParamsInput): string;
12
+ /**
13
+ * Parses the `X-Furin-Revalidate` response header and calls `invalidate` for
14
+ * each path entry. Header format: `"/path1,/path2:layout,/path3"`
15
+ */
16
+ export declare function applyRevalidateHeader(headers: Headers, invalidate: (path: string, type: "page" | "layout" | undefined) => void): void;
17
+ export declare function applyRevalidateEntries(entries: Iterable<string>, invalidate: (path: string, type: "page" | "layout" | undefined) => void): void;
18
+ /**
19
+ * Returns `true` when `currentPath` is targeted by at least one invalidation entry.
20
+ *
21
+ * @internal Exported for unit testing only.
22
+ */
23
+ export declare function shouldAutoRefreshPath(currentPath: string, invalidations: ReadonlyArray<{
24
+ path: string;
25
+ type: "page" | "layout";
26
+ }>): boolean;
27
+ export declare function stripHashFromHref(href: string): string;
28
+ /** Strips trailing slashes from a pathname or href. Root `/` is preserved.
29
+ * Query strings and hashes are preserved and re-attached after normalization. */
30
+ export declare function normalizeHref(href: string): string;
31
+ /** Strips a single trailing slash from a pathname. Root `/` and empty string are preserved. */
32
+ export declare function normalizePath(path: string): string;
33
+ /** @internal Exported for unit testing only. */
34
+ export declare function shouldRefetch(entry: CacheEntry): boolean;
35
+ /**
36
+ * Decides whether a native `<a>` click should be intercepted and converted
37
+ * to an SPA navigation. Returns the logical href to navigate to, or `null`
38
+ * when the browser should handle the click normally.
39
+ *
40
+ * @internal Exported for unit testing only.
41
+ */
42
+ export declare function shouldInterceptClick(anchor: {
43
+ href: string;
44
+ target: string;
45
+ hasAttribute(name: string): boolean;
46
+ }, event: {
47
+ metaKey: boolean;
48
+ ctrlKey: boolean;
49
+ shiftKey: boolean;
50
+ altKey: boolean;
51
+ }, basePath: string, currentOrigin: string, currentPathname: string): string | null;
52
+ /** Strips basePath prefix from a physical pathname, returning the logical path. */
53
+ export declare function toLogical(physicalPathname: string, basePath: string): string;
@@ -0,0 +1,10 @@
1
+ import type { RouteSearch, RouteTo } from "./types.ts";
2
+ export interface NavigateInput<To extends RouteTo> {
3
+ hash?: string;
4
+ replace?: boolean;
5
+ resetScroll?: boolean;
6
+ search?: RouteSearch<To>;
7
+ to: To;
8
+ }
9
+ export type Navigate = <To extends RouteTo>(next: NavigateInput<To>) => Promise<void>;
10
+ export declare function useNavigate(): Navigate;
@@ -0,0 +1,4 @@
1
+ import type React from "react";
2
+ import type { CacheEntry, RouterProviderProps } from "./types.ts";
3
+ export declare function setPrefetchCacheEntry(cache: Map<string, CacheEntry>, href: string, entry: CacheEntry, maxSize: number): void;
4
+ export declare function RouterProvider({ routes, root, initialMatch, initialData, initialDigest, initialNotFound, autoRefresh, basePath, defaultPreload, defaultPreloadDelay, defaultPreloadStaleTime, prefetchCacheSize, syncStream, }: RouterProviderProps): React.ReactElement;
@@ -0,0 +1,18 @@
1
+ import type { RouteManifest as LinkRouteManifest, RouteSearch, RouteTo } from "@teyik0/furin/link";
2
+ export interface RouteManifest extends LinkRouteManifest {
3
+ }
4
+ export type SearchRouteTo = keyof LinkRouteManifest extends never ? RouteTo : (string & {}) | keyof LinkRouteManifest;
5
+ type SearchRouteSearch<To extends SearchRouteTo> = keyof LinkRouteManifest extends never ? RouteSearch<To & RouteTo> : To extends keyof LinkRouteManifest ? LinkRouteManifest[To] extends {
6
+ search?: infer S;
7
+ } ? S : undefined : undefined;
8
+ export type EmptyRouteSearch = Record<PropertyKey, never>;
9
+ export type ResolvedRouteSearch<To extends SearchRouteTo> = SearchRouteSearch<To> extends never | undefined ? EmptyRouteSearch : NonNullable<SearchRouteSearch<To>>;
10
+ export type SetSearchInput<To extends SearchRouteTo> = Partial<ResolvedRouteSearch<To>> | ((prev: ResolvedRouteSearch<To>) => Partial<ResolvedRouteSearch<To>>);
11
+ export interface SetSearchOptions {
12
+ replace?: boolean;
13
+ resetScroll?: boolean;
14
+ }
15
+ export type SetSearch<To extends SearchRouteTo> = (next: SetSearchInput<To>, opts?: SetSearchOptions) => Promise<void>;
16
+ export declare function useSearch<To extends SearchRouteTo>(_from: To): [ResolvedRouteSearch<To>, SetSearch<To>];
17
+ export declare function useSearch<To extends SearchRouteTo, TSelected>(_from: To, selector: (search: ResolvedRouteSearch<To>) => TSelected): [TSelected, SetSearch<To>];
18
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
2
+ import type { RouterContextValue } from "./types.ts";
3
+ export interface SearchStoreSnapshot {
4
+ currentHref: string;
5
+ navigate: RouterContextValue["navigate"];
6
+ search: SearchParamsInput;
7
+ searchRoutes: SearchRouteMetadata[];
8
+ }
9
+ type SearchStoreListener = () => void;
10
+ export interface SearchStore {
11
+ flush: () => void;
12
+ getServerSnapshot: () => SearchStoreSnapshot;
13
+ getSnapshot: () => SearchStoreSnapshot;
14
+ setSnapshot: (next: SearchStoreSnapshot) => void;
15
+ subscribe: (listener: SearchStoreListener) => () => void;
16
+ }
17
+ export declare function createSearchStore(initialSnapshot: SearchStoreSnapshot): SearchStore;
18
+ export declare function searchSnapshotFromRouterContext(context: RouterContextValue): SearchStoreSnapshot;
19
+ export declare const FALLBACK_SEARCH_STORE: SearchStore;
20
+ export declare const SearchStoreContext: import("react").Context<SearchStore | null>;
21
+ export {};
@@ -0,0 +1,58 @@
1
+ import type React from "react";
2
+ import type { NotFoundComponent } from "../../shared/not-found.ts";
3
+ import type { ClientSegmentBoundary, SpaResponseKind } from "./types.ts";
4
+ /**
5
+ * Pure classifier for an SPA-nav fetch result. Takes the HTTP status and the
6
+ * already-parsed `__FURIN_DATA__` payload.
7
+ *
8
+ * Sentinels (`__furinError`, `__furinStatus`) are trusted over the raw HTTP
9
+ * status — proxies / CDNs sometimes rewrite the status code but pass the body
10
+ * through untouched. A non-2xx response without any sentinel triggers a bail
11
+ * so the browser handles it (could be an error page, redirect, etc.).
12
+ *
13
+ * @internal Exported for unit testing only.
14
+ */
15
+ export declare function classifySpaResponse(status: number, data: Record<string, unknown> | null): SpaResponseKind;
16
+ /**
17
+ * Picks the deepest not-found component declared on the match's boundary chain.
18
+ *
19
+ * @internal Exported for unit testing only.
20
+ */
21
+ export declare function pickDeepestNotFound(boundaries: ClientSegmentBoundary[] | undefined): NotFoundComponent | undefined;
22
+ /**
23
+ * Builds the bare not-found element rendered inline by RouterProvider on SPA
24
+ * navigation when the server signalled a 404.
25
+ *
26
+ * @internal Exported for unit testing only.
27
+ */
28
+ export declare function buildNotFoundPageElement(boundaries: ClientSegmentBoundary[] | undefined, error: {
29
+ data?: unknown;
30
+ message?: string;
31
+ }): React.ReactNode;
32
+ /**
33
+ * Parses the HTML payload of a page response into the pieces `fetchPageState`
34
+ * cares about: the document (for title), the __FURIN_DATA__ loader payload,
35
+ * and the logical `finalHref` after any server-side redirect.
36
+ */
37
+ export declare function parsePageResponse(res: Response, basePath: string): Promise<{
38
+ data: Record<string, unknown> | null;
39
+ finalHref: string | undefined;
40
+ title: string;
41
+ }>;
42
+ /**
43
+ * Builds the URL the SPA navigation flow uses to fetch a route's loader data.
44
+ *
45
+ * Two transports are supported:
46
+ *
47
+ * • **Runtime (SSR/ISR/dev)** — `${basePath}/_furin/data?path=<logicalHref>`.
48
+ * • **Static export** — `${basePath}<logicalPathname>/__furin_data.ndjson`.
49
+ *
50
+ * @internal Exported for unit testing.
51
+ */
52
+ export declare function buildDataEndpoint(basePath: string, logicalHref: string, staticMode: boolean): string;
53
+ /**
54
+ * Reads `<meta name="furin-mode" content="static">` from the document at boot.
55
+ *
56
+ * @internal Exported for unit testing.
57
+ */
58
+ export declare function detectStaticMode(): boolean;
@@ -0,0 +1,29 @@
1
+ export interface SyncChangePayload {
2
+ cursor: string;
3
+ invalidations: readonly string[];
4
+ }
5
+ export interface SyncChangePagePayload {
6
+ changes: readonly SyncChangePayload[];
7
+ cursor: string;
8
+ hasMore: boolean;
9
+ reset: boolean;
10
+ }
11
+ interface SyncCatchUpOptions {
12
+ fetchPage: (after: string | undefined) => Promise<SyncChangePagePayload>;
13
+ onInvalidations: (invalidations: readonly string[]) => void;
14
+ }
15
+ export interface SyncCatchUp {
16
+ catchUp(): Promise<void>;
17
+ cursor(): string | undefined;
18
+ initialize(): Promise<void>;
19
+ }
20
+ interface InvalidationRefreshOptions {
21
+ onError: (error: unknown) => void;
22
+ refresh: () => Promise<void>;
23
+ }
24
+ export interface InvalidationRefresh {
25
+ run(): Promise<void>;
26
+ }
27
+ export declare function createInvalidationRefresh(options: InvalidationRefreshOptions): InvalidationRefresh;
28
+ export declare function createSyncCatchUp(options: SyncCatchUpOptions): SyncCatchUp;
29
+ export {};
@@ -0,0 +1,292 @@
1
+ import type React from "react";
2
+ import type { RuntimeRoute } from "../../client.ts";
3
+ import type { ErrorComponent } from "../../shared/error.ts";
4
+ import type { NotFoundComponent } from "../../shared/not-found.ts";
5
+ import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
6
+ /**
7
+ * Augment this interface via declaration merging in furin-env.d.ts
8
+ * to get type-safe `to` autocompletion and per-route `search` types on <Link>.
9
+ *
10
+ * @example
11
+ * // furin-env.d.ts (auto-generated by Furin at project root)
12
+ * import "@teyik0/furin/link";
13
+ * declare module "@teyik0/furin/link" {
14
+ * interface RouteManifest {
15
+ * "/blog": { search?: { page?: number; tag?: string } };
16
+ * "/": { search?: never };
17
+ * [key: `/blog/${string}`]: { search?: never };
18
+ * }
19
+ * }
20
+ */
21
+ export interface RouteManifest {
22
+ }
23
+ /**
24
+ * The valid `to` pathname union derived from the augmented RouteManifest.
25
+ * Falls back to `string` when furin-env.d.ts has not been generated yet.
26
+ * When augmented, also includes `https://` and `http://` for external links.
27
+ */
28
+ export type RouteTo = keyof RouteManifest extends never ? string : (string & {}) | keyof RouteManifest | `https://${string}` | `http://${string}`;
29
+ /**
30
+ * The typed search params for a given `to` pathname.
31
+ * Falls back to a permissive record when RouteManifest is not augmented.
32
+ */
33
+ export type RouteSearch<To extends RouteTo> = keyof RouteManifest extends never ? SearchParamsInput : To extends keyof RouteManifest ? RouteManifest[To] extends {
34
+ searchInput?: infer I;
35
+ } ? I : RouteManifest[To] extends {
36
+ search?: infer S;
37
+ } ? S : undefined : undefined;
38
+ export type PreloadStrategy = false | "intent" | "viewport" | "render";
39
+ export interface LinkProps<To extends RouteTo = RouteTo> extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "children"> {
40
+ /**
41
+ * Extra props merged onto the anchor when the link is active.
42
+ * `isActive` is also passed so one function can handle both states.
43
+ * Styles and classNames from `activeProps` win over the static props.
44
+ */
45
+ activeProps?: (opts: {
46
+ isActive: boolean;
47
+ }) => React.AnchorHTMLAttributes<HTMLAnchorElement>;
48
+ /** Static children or a render function receiving active state. */
49
+ children?: React.ReactNode | ((state: {
50
+ isActive: boolean;
51
+ }) => React.ReactNode);
52
+ /** Prevents navigation and prefetch; adds aria-disabled="true". The href stays intact for right-click. */
53
+ disabled?: boolean;
54
+ /** Optional URL fragment (without the #). */
55
+ hash?: string;
56
+ /**
57
+ * Extra props merged onto the anchor when the link is NOT active.
58
+ * Styles and classNames from `inactiveProps` win over the static props.
59
+ */
60
+ inactiveProps?: () => React.AnchorHTMLAttributes<HTMLAnchorElement>;
61
+ /** Preload strategy. Default: "intent" (preload on hover/focus). */
62
+ preload?: PreloadStrategy;
63
+ /** Delay in ms before intent preload triggers. Default: 50. */
64
+ preloadDelay?: number;
65
+ /** How long a preloaded entry stays fresh (ms). Default: 30_000. */
66
+ preloadStaleTime?: number;
67
+ /** If true, uses history.replaceState instead of pushState (no new history entry). */
68
+ replace?: boolean;
69
+ /**
70
+ * Whether to scroll after SPA navigation. Default: true.
71
+ * - If the destination href has a `#hash`, scrolls to that element.
72
+ * - Otherwise scrolls to the top of the page.
73
+ * Set to `false` to suppress all scroll behaviour (e.g. tab/drawer navigation).
74
+ */
75
+ resetScroll?: boolean;
76
+ /** Typed search params for this route. Auto-completed from the route's query schema. */
77
+ search?: RouteSearch<To>;
78
+ to: To;
79
+ }
80
+ export interface RouterContextValue {
81
+ /**
82
+ * Sub-path prefix for static deployments (e.g. "/furin").
83
+ * Empty string when the site is served from root.
84
+ * Used by `Link` to build correct physical hrefs for the `<a>` element.
85
+ */
86
+ basePath: string;
87
+ /** Current **logical** pathname + search (basePath stripped). Used by Link for active-state detection. */
88
+ currentHref: string;
89
+ defaultPreload: PreloadStrategy;
90
+ defaultPreloadDelay: number;
91
+ defaultPreloadStaleTime: number;
92
+ /**
93
+ * Evicts one or more prefetch cache entries, mirroring a `revalidatePath()` call
94
+ * made on the server. Called automatically by the `window.fetch` interceptor when
95
+ * the server emits `X-Furin-Revalidate` headers.
96
+ *
97
+ * - `type: 'page'` (default) — exact URL match
98
+ * - `type: 'layout'` — prefix match (path + all nested children)
99
+ */
100
+ invalidatePrefetch: (path: string, type: "page" | "layout") => void;
101
+ isNavigating: boolean;
102
+ navigate: (href: string, opts?: {
103
+ replace?: boolean;
104
+ resetScroll?: boolean;
105
+ }) => Promise<void>;
106
+ prefetch: (href: string, opts?: {
107
+ staleTime?: number;
108
+ }) => void;
109
+ /**
110
+ * Re-fetches the current page in-place: busts the prefetch cache entry, re-runs
111
+ * loaders, and updates the rendered tree — without adding a history entry or
112
+ * resetting scroll (unless `resetScroll: true` is passed).
113
+ *
114
+ * Prefer this over `navigate(window.location.pathname)` after a mutation.
115
+ */
116
+ refresh: (opts?: {
117
+ resetScroll?: boolean;
118
+ }) => Promise<void>;
119
+ /** Current server-resolved query params for the rendered route. */
120
+ search: SearchParamsInput;
121
+ /** Route-level search defaults used to build clean hrefs without default params. */
122
+ searchRoutes: SearchRouteMetadata[];
123
+ }
124
+ /**
125
+ * Client-side mirror of `SegmentBoundary` from router.ts. Unlike the server
126
+ * version this does NOT carry the directory path — it's purely a (depth,
127
+ * fallback) pair because the client never reads files, only renders.
128
+ */
129
+ export interface ClientSegmentBoundary {
130
+ depth: number;
131
+ error?: ErrorComponent;
132
+ notFound?: NotFoundComponent;
133
+ }
134
+ export interface ClientRoute {
135
+ component?: React.ComponentType<Record<string, unknown>>;
136
+ load: () => Promise<{
137
+ default: {
138
+ component: React.ComponentType<Record<string, unknown>>;
139
+ _route: RuntimeRoute;
140
+ };
141
+ segmentBoundaries?: ClientSegmentBoundary[];
142
+ }>;
143
+ pageRoute?: RuntimeRoute;
144
+ pattern: string;
145
+ regex: RegExp;
146
+ searchDefaults?: SearchParamsInput;
147
+ /**
148
+ * Per-segment boundary chain, ordered shallow→deep. Each `depth` maps 1:1
149
+ * to the route-chain index used on the server side, so `buildPageElement`
150
+ * can interleave boundaries at the exact same positions that the server
151
+ * used in `buildElement` — guaranteeing hydration consistency.
152
+ */
153
+ segmentBoundaries?: ClientSegmentBoundary[];
154
+ }
155
+ /**
156
+ * A ClientRoute that has been loaded — component and pageRoute are guaranteed defined.
157
+ * The initial route is eagerly loaded in the hydrate entry; subsequent routes are loaded
158
+ * on navigation via fetchPageState.
159
+ */
160
+ export type LoadedClientRoute = ClientRoute & {
161
+ component: React.ComponentType<Record<string, unknown>>;
162
+ pageRoute: RuntimeRoute;
163
+ };
164
+ export interface RouterProviderProps {
165
+ /**
166
+ * When `true` (default), the router automatically re-fetches the current page
167
+ * whenever a server `revalidatePath()` call targets it. The signal is the
168
+ * `X-Furin-Revalidate` header detected on any `window.fetch` response.
169
+ *
170
+ * Set to `false` to opt out and call `router.refresh()` manually instead.
171
+ */
172
+ autoRefresh: boolean;
173
+ /**
174
+ * Sub-path prefix for static deployments (e.g. "/furin").
175
+ * Must start with "/" and have no trailing slash.
176
+ * Default: "" (site served from root).
177
+ */
178
+ basePath: string;
179
+ defaultPreload: PreloadStrategy;
180
+ defaultPreloadDelay: number;
181
+ defaultPreloadStaleTime: number;
182
+ initialData: Record<string, unknown>;
183
+ /**
184
+ * Slice 10 — server-logged error digest threaded from
185
+ * `__FURIN_DATA__.__furinError.digest`. Forwarded onto the root-level
186
+ * `FurinErrorBoundary` so that if a client-side error escapes the
187
+ * per-segment boundaries (root layout crash, hydration mismatch, …), the
188
+ * fallback UI surfaces the id a user would find in server logs.
189
+ */
190
+ initialDigest: string | undefined;
191
+ /**
192
+ * The route matched at hydration time. `null` is a valid value ONLY when
193
+ * `initialNotFound` is also provided.
194
+ */
195
+ initialMatch: LoadedClientRoute | null;
196
+ /**
197
+ * When set, the provider boots into the inline not-found state as if a
198
+ * prior SPA navigation hit a 404.
199
+ */
200
+ initialNotFound: {
201
+ data?: unknown;
202
+ message?: string;
203
+ } | undefined;
204
+ /** Maximum number of prefetch cache entries. Oldest entry is evicted when exceeded. Default: 50. */
205
+ prefetchCacheSize: number;
206
+ root: RuntimeRoute | null;
207
+ routes: ClientRoute[];
208
+ /**
209
+ * Optional internal SSE endpoint emitted by `furin({ sync: true })`.
210
+ * When present, RouterProvider listens for cross-client invalidations.
211
+ */
212
+ syncStream?: string | undefined;
213
+ }
214
+ /** @internal Router state held inside RouterProvider. Exported so CacheEntry can reference it. */
215
+ export interface RouterState {
216
+ data: Record<string, unknown>;
217
+ /**
218
+ * Set when the server's NDJSON payload carried an `__furinError` sentinel.
219
+ */
220
+ error?: {
221
+ digest: string;
222
+ message: string;
223
+ status: number;
224
+ };
225
+ /** The canonical href after server-side redirects (e.g. query-default redirect). */
226
+ finalHref?: string;
227
+ /**
228
+ * The currently rendered route.
229
+ *
230
+ * `null` is a valid value ONLY when `notFound` is also set.
231
+ */
232
+ match: LoadedClientRoute | null;
233
+ /**
234
+ * Slice 8 — set when the matched route's loader threw `notFound()` on the server.
235
+ */
236
+ notFound?: {
237
+ data?: unknown;
238
+ message?: string;
239
+ };
240
+ /**
241
+ * Explicit boundary chain to use for the not-found render.
242
+ */
243
+ notFoundBoundaries?: ClientSegmentBoundary[] | undefined;
244
+ title?: string;
245
+ }
246
+ /** @internal */
247
+ export interface CacheEntry {
248
+ createdAt: number;
249
+ promise: Promise<RouterState | null>;
250
+ staleTime: number;
251
+ }
252
+ /**
253
+ * Classification of a fetch response during SPA navigation. Returned by the
254
+ * pure `classifySpaResponse` so `fetchPageState` stays a thin orchestrator.
255
+ *
256
+ * - `ok` — 2xx response with usable loader data; render normally.
257
+ * - `not-found` — server signalled `__FURIN_DATA__.__furinStatus === 404`.
258
+ * - `error` — server signalled `__FURIN_DATA__.__furinError`.
259
+ * - `bail` — any other non-2xx without sentinels.
260
+ *
261
+ * @internal Exported for unit testing only.
262
+ */
263
+ export type SpaResponseKind = {
264
+ kind: "ok";
265
+ } | {
266
+ kind: "not-found";
267
+ error: {
268
+ data?: unknown;
269
+ message?: string;
270
+ };
271
+ } | {
272
+ kind: "error";
273
+ error: {
274
+ digest: string;
275
+ message: string;
276
+ status: number;
277
+ };
278
+ } | {
279
+ kind: "bail";
280
+ };
281
+ /**
282
+ * Root-level safety-net options forwarded onto the outermost
283
+ * `FurinErrorBoundary` that wraps the entire RouterProvider tree.
284
+ */
285
+ export interface RootBoundaryOptions {
286
+ /**
287
+ * Server-logged error id propagated from `__FURIN_DATA__.__furinError.digest`.
288
+ */
289
+ digest?: string;
290
+ onReset?: () => void;
291
+ resetKey?: string | number;
292
+ }
@@ -0,0 +1,12 @@
1
+ export interface FurinServerErrorPayload {
2
+ digest: string;
3
+ message: string;
4
+ status: number;
5
+ }
6
+ export declare class FurinServerError extends Error {
7
+ readonly __furinBrand: "FURIN_SERVER_ERROR";
8
+ readonly digest: string;
9
+ readonly status: number;
10
+ constructor(args: FurinServerErrorPayload);
11
+ }
12
+ export declare function isFurinServerError(err: unknown): err is FurinServerError;
@@ -0,0 +1,25 @@
1
+ export interface SyncMutationHeaders {
2
+ "Idempotency-Key": string;
3
+ }
4
+ export interface SyncMutationOptions {
5
+ headers: SyncMutationHeaders;
6
+ }
7
+ export interface SyncMutationContext<TInput> {
8
+ idempotencyKey: string;
9
+ input: TInput;
10
+ }
11
+ export interface SyncMutationSuccessContext<TInput, TResult> extends SyncMutationContext<TInput> {
12
+ result: TResult;
13
+ }
14
+ export interface SyncMutationErrorContext<TInput, TResult> extends SyncMutationContext<TInput> {
15
+ error: unknown;
16
+ result?: TResult;
17
+ }
18
+ export interface UseSyncOptions<TInput, TResult> {
19
+ onError?: (ctx: SyncMutationErrorContext<TInput, TResult>) => Promise<void> | void;
20
+ onSuccess?: (ctx: SyncMutationSuccessContext<TInput, TResult>) => Promise<void> | void;
21
+ optimistic?: (ctx: SyncMutationContext<TInput>) => (() => void) | undefined;
22
+ }
23
+ export type SyncMutation<TInput, TResult> = (input: TInput, options: SyncMutationOptions) => Promise<TResult>;
24
+ export type SyncMutationRunner<TInput, TResult> = undefined extends TInput ? (input?: TInput) => Promise<TResult> : (input: TInput) => Promise<TResult>;
25
+ export declare function useSync<TInput, TResult>(mutation: SyncMutation<TInput, TResult>, options?: UseSyncOptions<TInput, TResult>): SyncMutationRunner<TInput, TResult>;