@teyik0/furin 0.9.0-alpha.0 → 0.9.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/README.md +1 -1
- package/dist/adapter/runtime-build.d.ts +7 -3
- package/dist/adapter/vercel.js +31 -6
- package/dist/build/client.d.ts +1 -1
- package/dist/build/entry-template.d.ts +3 -12
- package/dist/build/entry-template.ts +3 -15
- package/dist/build/hydrate.d.ts +6 -1
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +565 -401
- package/dist/build/route-metadata.d.ts +2 -2
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +10 -4
- package/dist/cli/dev-worker.ts +10 -4
- package/dist/cli/index.js +624 -445
- package/dist/client/chunks/{client-xy6g38kx.js → client-a7spxfnn.js} +24 -5
- package/dist/client/chunks/{client-rjhxgt64.js → client-d9v49jwz.js} +1 -1
- package/dist/client/chunks/{client-k29262a4.js → client-rdxyrw11.js} +1 -1
- package/dist/client/define-route.d.ts +14 -0
- package/dist/client/internal/runtime-types.d.ts +8 -0
- package/dist/client/link.js +20 -17
- package/dist/client/router/link-utils.d.ts +3 -2
- package/dist/client/router/search/index.js +2 -2
- package/dist/client/router/types.d.ts +9 -3
- package/dist/client.js +22 -6
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -1
- package/dist/define-route.d.ts +53 -12
- package/dist/furin.d.ts +13 -3
- package/dist/furin.js +815 -661
- package/dist/plugin/route-config.d.ts +3 -3
- package/dist/plugin/route-manifest.d.ts +46 -0
- package/dist/plugin/route-tree.d.ts +13 -29
- package/dist/routes.d.ts +2 -2
- package/dist/server/dev/runtime.d.ts +2 -1
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +97 -114
- package/dist/server/registrations.d.ts +4 -2
- package/dist/server/render/index.d.ts +0 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/shell.d.ts +1 -13
- package/dist/server/render/shell.ts +1 -90
- package/dist/server/router/defined-route.d.ts +4 -0
- package/dist/server/router/discovery.d.ts +14 -4
- package/dist/server/router/hmr.d.ts +12 -12
- package/dist/server/router/patterns.d.ts +4 -12
- package/dist/server/router/types.d.ts +16 -1
- package/dist/server/static-export.js +128 -158
- package/dist/server/sync/drizzle/index.d.ts +8 -10
- package/dist/shared/not-found.d.ts +1 -1
- package/dist/shared/route-specificity.d.ts +10 -1
- package/package.json +8 -11
- package/src/adapter/package.ts +11 -37
- package/src/adapter/runtime-build.ts +5 -4
- package/src/adapter/static.ts +1 -1
- package/src/adapter/vercel.ts +2 -1
- package/src/build/client.ts +3 -3
- package/src/build/discover-pages-process.ts +1 -1
- package/src/build/elysia-aot.ts +2 -2
- package/src/build/entry-template.ts +3 -15
- package/src/build/hydrate.ts +12 -6
- package/src/build/index.ts +19 -9
- package/src/build/route-metadata.ts +15 -8
- package/src/build/route-types.ts +18 -43
- package/src/build/types.ts +12 -5
- package/src/cli/config.ts +6 -0
- package/src/cli/dev-worker.ts +10 -4
- package/src/cli/dev.ts +41 -26
- package/src/cli/index.ts +30 -14
- package/src/client/define-route.ts +29 -4
- package/src/client/internal/runtime-types.ts +8 -0
- package/src/client/link.tsx +21 -22
- package/src/client/router/context.ts +8 -7
- package/src/client/router/link-utils.ts +16 -8
- package/src/client/router/provider.tsx +5 -0
- package/src/client/router/types.ts +40 -14
- package/src/config.ts +5 -0
- package/src/define-route.ts +85 -16
- package/src/furin.ts +31 -7
- package/src/plugin/dev-routes.ts +8 -17
- package/src/plugin/route-config.ts +77 -62
- package/src/plugin/route-manifest.ts +437 -0
- package/src/plugin/route-modules.ts +6 -1
- package/src/plugin/route-registry.ts +7 -21
- package/src/plugin/route-tree.ts +71 -181
- package/src/routes.ts +2 -2
- package/src/server/dev/runtime.ts +16 -22
- package/src/server/internal.ts +4 -1
- package/src/server/registrations.ts +5 -2
- package/src/server/render/index.ts +0 -1
- package/src/server/render/shell.ts +1 -90
- package/src/server/render/static-params.ts +2 -10
- package/src/server/router/defined-route.ts +8 -0
- package/src/server/router/discovery.ts +237 -196
- package/src/server/router/hmr.ts +45 -63
- package/src/server/router/patterns.ts +41 -117
- package/src/server/router/types.ts +17 -1
- package/src/server/sync/drizzle/index.ts +18 -19
- package/src/shared/not-found.ts +1 -1
- package/src/shared/route-specificity.ts +34 -2
- package/src/shared/utils/index.ts +1 -1
|
@@ -40,7 +40,7 @@ function segmentSpecificity(segment) {
|
|
|
40
40
|
}
|
|
41
41
|
return segment.startsWith(":") ? 2 : 3;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function compareConcreteSpecificity(a, b) {
|
|
44
44
|
const aSegments = a.split("/").filter(Boolean);
|
|
45
45
|
const bSegments = b.split("/").filter(Boolean);
|
|
46
46
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
@@ -60,6 +60,24 @@ function compareRouteSpecificity(a, b) {
|
|
|
60
60
|
}
|
|
61
61
|
return 0;
|
|
62
62
|
}
|
|
63
|
+
function expandOptionalSegments(pattern) {
|
|
64
|
+
let variants = [[]];
|
|
65
|
+
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
66
|
+
if (segment.startsWith(":") && segment.endsWith("?")) {
|
|
67
|
+
const required = segment.slice(0, -1);
|
|
68
|
+
variants = variants.flatMap((variant) => [variant, [...variant, required]]);
|
|
69
|
+
} else {
|
|
70
|
+
variants = variants.map((variant) => [...variant, segment]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return variants.map((variant) => `/${variant.join("/")}`);
|
|
74
|
+
}
|
|
75
|
+
function mostSpecificVariant(pattern) {
|
|
76
|
+
return expandOptionalSegments(pattern).reduce((best, variant) => compareConcreteSpecificity(variant, best) > 0 ? variant : best);
|
|
77
|
+
}
|
|
78
|
+
function compareRouteSpecificity(a, b) {
|
|
79
|
+
return compareConcreteSpecificity(mostSpecificVariant(a), mostSpecificVariant(b));
|
|
80
|
+
}
|
|
63
81
|
|
|
64
82
|
// src/shared/search-params.ts
|
|
65
83
|
function isObject(value) {
|
|
@@ -206,11 +224,12 @@ function isSameOriginFetchResult(input, responseUrl, currentOrigin) {
|
|
|
206
224
|
}
|
|
207
225
|
}
|
|
208
226
|
function applyLinkParams(to, params) {
|
|
209
|
-
|
|
210
|
-
|
|
227
|
+
const values = params ?? {};
|
|
228
|
+
let url = to.replaceAll(/\/:([a-zA-Z0-9_]+)\?(?=\/|$)/g, (_match, name) => values[name] === undefined || values[name] === "" ? "" : `/${encodeURIComponent(String(values[name]))}`).replaceAll(/:([a-zA-Z0-9_]+)/g, (match, name) => (name in values) ? encodeURIComponent(String(values[name])) : match);
|
|
229
|
+
if (url === "") {
|
|
230
|
+
url = "/";
|
|
211
231
|
}
|
|
212
|
-
|
|
213
|
-
const wildcard = params["*"];
|
|
232
|
+
const wildcard = values._splat;
|
|
214
233
|
if (wildcard !== undefined && url.includes("/*")) {
|
|
215
234
|
const encodedWildcard = String(wildcard).split("/").map(encodeURIComponent).join("/");
|
|
216
235
|
url = url.replace("/*", () => `/${encodedWildcard}`);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ErrorComponent } from "../shared/error.ts";
|
|
2
|
+
import type { NotFoundComponent } from "../shared/not-found.ts";
|
|
1
3
|
import type { RemountDeps } from "../shared/page-key.ts";
|
|
2
4
|
type ClientComponent = (props: never) => React.ReactNode;
|
|
3
5
|
interface ClientRuntimeProps {
|
|
@@ -13,14 +15,20 @@ export declare function defineRoute(_id: string): {
|
|
|
13
15
|
config(options: {
|
|
14
16
|
remountDeps?: RemountDeps<never, never>;
|
|
15
17
|
}): /*elided*/ any;
|
|
18
|
+
error(component: ErrorComponent): /*elided*/ any;
|
|
16
19
|
layout<Component extends ClientComponent>(component: Component): {
|
|
17
20
|
__type: "FURIN_ROUTE";
|
|
18
21
|
component: ClientRuntimeComponent;
|
|
22
|
+
errorComponent: ErrorComponent | undefined;
|
|
19
23
|
layout: ClientRuntimeComponent;
|
|
24
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
20
25
|
};
|
|
26
|
+
notFound(component: NotFoundComponent): /*elided*/ any;
|
|
21
27
|
page<Component extends ClientComponent>(component: Component): {
|
|
22
28
|
__type: "FURIN_ROUTE";
|
|
23
29
|
component: ClientRuntimeComponent;
|
|
30
|
+
errorComponent: ErrorComponent | undefined;
|
|
31
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
24
32
|
page: ClientRuntimeComponent;
|
|
25
33
|
remountDeps: RemountDeps<never, never> | undefined;
|
|
26
34
|
};
|
|
@@ -30,14 +38,20 @@ export declare function defineRootRoute(): {
|
|
|
30
38
|
config(options: {
|
|
31
39
|
remountDeps?: RemountDeps<never, never>;
|
|
32
40
|
}): /*elided*/ any;
|
|
41
|
+
error(component: ErrorComponent): /*elided*/ any;
|
|
33
42
|
layout<Component extends ClientComponent>(component: Component): {
|
|
34
43
|
__type: "FURIN_ROUTE";
|
|
35
44
|
component: ClientRuntimeComponent;
|
|
45
|
+
errorComponent: ErrorComponent | undefined;
|
|
36
46
|
layout: ClientRuntimeComponent;
|
|
47
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
37
48
|
};
|
|
49
|
+
notFound(component: NotFoundComponent): /*elided*/ any;
|
|
38
50
|
page<Component extends ClientComponent>(component: Component): {
|
|
39
51
|
__type: "FURIN_ROUTE";
|
|
40
52
|
component: ClientRuntimeComponent;
|
|
53
|
+
errorComponent: ErrorComponent | undefined;
|
|
54
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
41
55
|
page: ClientRuntimeComponent;
|
|
42
56
|
remountDeps: RemountDeps<never, never> | undefined;
|
|
43
57
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
import type { HeadOptions, RenderingMode } from "../../client.ts";
|
|
3
3
|
import type { RequestLoaderContext } from "../../define-route.ts";
|
|
4
|
+
import type { ErrorComponent } from "../../shared/error.ts";
|
|
5
|
+
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
4
6
|
import type { RemountDeps } from "../../shared/page-key.ts";
|
|
5
7
|
/**
|
|
6
8
|
* Loader data after type erasure: field name → value. Each route declares the
|
|
@@ -18,11 +20,15 @@ export type RuntimeStaticParams = (context: RuntimeData & {
|
|
|
18
20
|
}) => Awaitable<readonly RuntimeParams[]>;
|
|
19
21
|
export interface RuntimeRoute {
|
|
20
22
|
__type: "FURIN_ROUTE";
|
|
23
|
+
/** TanStack style: `.error()` of the route. */
|
|
24
|
+
errorComponent?: ErrorComponent;
|
|
21
25
|
layout?: React.FC<RuntimeData & {
|
|
22
26
|
children: React.ReactNode;
|
|
23
27
|
}>;
|
|
24
28
|
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
25
29
|
mode?: RenderingMode;
|
|
30
|
+
/** TanStack style: `.notFound()` of the route. */
|
|
31
|
+
notFoundComponent?: NotFoundComponent;
|
|
26
32
|
params?: unknown;
|
|
27
33
|
parent?: RuntimeRoute;
|
|
28
34
|
query?: unknown;
|
|
@@ -37,9 +43,11 @@ export interface RuntimePage {
|
|
|
37
43
|
__type: "FURIN_PAGE";
|
|
38
44
|
_route: RuntimeRoute;
|
|
39
45
|
component: React.FC<RuntimeData>;
|
|
46
|
+
errorComponent?: ErrorComponent;
|
|
40
47
|
head?: (ctx: RuntimeData) => HeadOptions;
|
|
41
48
|
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
42
49
|
mode?: RenderingMode;
|
|
50
|
+
notFoundComponent?: NotFoundComponent;
|
|
43
51
|
revalidate?: number;
|
|
44
52
|
staticParams?: RuntimeStaticParams;
|
|
45
53
|
tags?: string[];
|
package/dist/client/link.js
CHANGED
|
@@ -14,14 +14,14 @@ import {
|
|
|
14
14
|
isAbortError,
|
|
15
15
|
createInvalidationRefresh,
|
|
16
16
|
createSyncCatchUp
|
|
17
|
-
} from "./chunks/client-
|
|
17
|
+
} from "./chunks/client-d9v49jwz.js";
|
|
18
18
|
import {
|
|
19
19
|
restoreRscSource2
|
|
20
20
|
} from "./chunks/client-k88668k7.js";
|
|
21
21
|
import {
|
|
22
22
|
createSearchStore,
|
|
23
23
|
SearchStoreContext
|
|
24
|
-
} from "./chunks/client-
|
|
24
|
+
} from "./chunks/client-rdxyrw11.js";
|
|
25
25
|
import {
|
|
26
26
|
physicalPath,
|
|
27
27
|
isWithinPrefix,
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
shouldRefetch2,
|
|
42
42
|
shouldInterceptClick2,
|
|
43
43
|
toLogical2
|
|
44
|
-
} from "./chunks/client-
|
|
44
|
+
} from "./chunks/client-a7spxfnn.js";
|
|
45
45
|
|
|
46
46
|
// src/client/link.tsx
|
|
47
47
|
import { createElement as createElement2, useCallback as useCallback3, useEffect as useEffect6, useRef as useRef3, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
@@ -92,8 +92,9 @@ function useRouterStore() {
|
|
|
92
92
|
return { getCurrentHref: () => value.currentHref, router: value, subscribe: subscribeNever };
|
|
93
93
|
}
|
|
94
94
|
function useTypedNavigation(context) {
|
|
95
|
+
const { navigate: navigateHref, prefetch: prefetchHref, searchRoutes } = context;
|
|
95
96
|
const navigate = useCallback((next, opts) => {
|
|
96
|
-
const href = typeof next === "string" ? next : resolveRouteTarget(next,
|
|
97
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
97
98
|
const policy = navigationHrefPolicy(href, typeof window === "undefined" ? undefined : window.location.origin);
|
|
98
99
|
if (policy === "blocked") {
|
|
99
100
|
return Promise.reject(new Error("[furin] Unsafe navigation URL."));
|
|
@@ -103,19 +104,19 @@ function useTypedNavigation(context) {
|
|
|
103
104
|
return Promise.resolve();
|
|
104
105
|
}
|
|
105
106
|
if (typeof next === "string") {
|
|
106
|
-
return
|
|
107
|
+
return navigateHref(href, opts);
|
|
107
108
|
}
|
|
108
109
|
const options = next.replace === undefined && next.resetScroll === undefined ? undefined : { replace: next.replace, resetScroll: next.resetScroll };
|
|
109
|
-
return
|
|
110
|
-
}, [
|
|
110
|
+
return navigateHref(href, options);
|
|
111
|
+
}, [navigateHref, searchRoutes]);
|
|
111
112
|
const prefetch = useCallback((next, opts) => {
|
|
112
|
-
const href = typeof next === "string" ? next : resolveRouteTarget(next,
|
|
113
|
+
const href = typeof next === "string" ? next : resolveRouteTarget(next, searchRoutes);
|
|
113
114
|
const policy = navigationHrefPolicy(href, typeof window === "undefined" ? undefined : window.location.origin);
|
|
114
115
|
if (policy !== "internal") {
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
}, [
|
|
118
|
+
prefetchHref(href, typeof next === "string" ? opts : { staleTime: next.staleTime });
|
|
119
|
+
}, [prefetchHref, searchRoutes]);
|
|
119
120
|
return { navigate, prefetch };
|
|
120
121
|
}
|
|
121
122
|
function useRouter() {
|
|
@@ -3619,6 +3620,7 @@ function RouterProvider({
|
|
|
3619
3620
|
});
|
|
3620
3621
|
}
|
|
3621
3622
|
// src/client/link.tsx
|
|
3623
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
3622
3624
|
"use client";
|
|
3623
3625
|
function resolveLinkHref({ to, params, search, hash }, router2) {
|
|
3624
3626
|
const resolvedTo = applyLinkParams(to, params);
|
|
@@ -3687,12 +3689,12 @@ function LinkInteractive({
|
|
|
3687
3689
|
if (target !== null) {
|
|
3688
3690
|
prefetch(target, { staleTime: effectiveStaleTime });
|
|
3689
3691
|
}
|
|
3690
|
-
}, [prefetch,
|
|
3692
|
+
}, [prefetch, effectiveStaleTime, router2.basePath]);
|
|
3691
3693
|
useEffect6(() => {
|
|
3692
3694
|
if (effectivePreload === "render") {
|
|
3693
3695
|
triggerPrefetch();
|
|
3694
3696
|
}
|
|
3695
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3697
|
+
}, [effectivePreload, triggerPrefetch, logicalHref]);
|
|
3696
3698
|
useEffect6(() => {
|
|
3697
3699
|
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
3698
3700
|
return;
|
|
@@ -3705,7 +3707,7 @@ function LinkInteractive({
|
|
|
3705
3707
|
}, { rootMargin: "200px" });
|
|
3706
3708
|
observer.observe(anchorRef.current);
|
|
3707
3709
|
return () => observer.disconnect();
|
|
3708
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3710
|
+
}, [effectivePreload, triggerPrefetch, logicalHref]);
|
|
3709
3711
|
useEffect6(() => () => {
|
|
3710
3712
|
if (intentTimerRef.current !== null) {
|
|
3711
3713
|
clearTimeout(intentTimerRef.current);
|
|
@@ -3734,7 +3736,7 @@ function LinkInteractive({
|
|
|
3734
3736
|
}
|
|
3735
3737
|
e.preventDefault();
|
|
3736
3738
|
if (typeof window !== "undefined" && router2.navigate === CLIENT_FALLBACK_ROUTER.navigate) {
|
|
3737
|
-
window.location.href
|
|
3739
|
+
window.location.assign(href);
|
|
3738
3740
|
return;
|
|
3739
3741
|
}
|
|
3740
3742
|
router2.navigate(target, { replace, resetScroll: resetScroll ?? true });
|
|
@@ -3758,7 +3760,7 @@ function LinkInteractive({
|
|
|
3758
3760
|
triggerPrefetch();
|
|
3759
3761
|
}
|
|
3760
3762
|
};
|
|
3761
|
-
return
|
|
3763
|
+
return /* @__PURE__ */ jsx5("a", {
|
|
3762
3764
|
"data-furin-link": true,
|
|
3763
3765
|
href,
|
|
3764
3766
|
onClick: handleClick,
|
|
@@ -3769,8 +3771,9 @@ function LinkInteractive({
|
|
|
3769
3771
|
...isActive ? { "data-status": "active" } : {},
|
|
3770
3772
|
...anchorProps,
|
|
3771
3773
|
...extraProps,
|
|
3772
|
-
...disabled ? { "aria-disabled": true } : {}
|
|
3773
|
-
|
|
3774
|
+
...disabled ? { "aria-disabled": true } : {},
|
|
3775
|
+
children: resolvedChildren
|
|
3776
|
+
});
|
|
3774
3777
|
}
|
|
3775
3778
|
var SSR_FALLBACK_ROUTER = {
|
|
3776
3779
|
basePath: "",
|
|
@@ -8,8 +8,9 @@ export declare function decodeHashFragment(fragment: string): string;
|
|
|
8
8
|
export declare function isSameOriginFetchResult(input: RequestInfo | URL, responseUrl: string, currentOrigin: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Substitutes typed path params into a route pattern: `/board/:boardId` with
|
|
11
|
-
* `{ boardId: 42 }` → `/board/42`.
|
|
12
|
-
*
|
|
11
|
+
* `{ boardId: 42 }` → `/board/42`. An optional `/:lang?` segment is dropped
|
|
12
|
+
* when its param is absent. The `*` wildcard segment (catch-all) is
|
|
13
|
+
* replaced from `params._splat`. Unknown segments are left untouched so
|
|
13
14
|
* partially-applied patterns stay visible.
|
|
14
15
|
*
|
|
15
16
|
* @internal Exported for unit testing only.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FALLBACK_SEARCH_STORE,
|
|
3
3
|
SearchStoreContext
|
|
4
|
-
} from "../../chunks/client-
|
|
4
|
+
} from "../../chunks/client-rdxyrw11.js";
|
|
5
5
|
import {
|
|
6
6
|
findSearchDefaultsForRouteTarget,
|
|
7
7
|
buildHref2
|
|
8
|
-
} from "../../chunks/client-
|
|
8
|
+
} from "../../chunks/client-a7spxfnn.js";
|
|
9
9
|
|
|
10
10
|
// src/client/router/search/index.ts
|
|
11
11
|
import { useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
@@ -14,8 +14,14 @@ export type RouteManifest = RouteMap;
|
|
|
14
14
|
export type RoutePattern = keyof RouteManifest & string;
|
|
15
15
|
type HrefPath<Href extends string> = Href extends `${infer Path}?${string}` ? HrefPath<Path> : Href extends `${infer Path}#${string}` ? Path : Href;
|
|
16
16
|
type SegmentMatches<PatternSegment extends string, Segment extends string> = PatternSegment extends `:${string}` ? Segment extends "" ? false : true : [Segment] extends [PatternSegment] ? true : false;
|
|
17
|
-
/**
|
|
18
|
-
type
|
|
17
|
+
/** An optional `:param?` segment followed by `Rest`: skip it, or let it take one segment. */
|
|
18
|
+
type OptionalSegmentMatches<Rest extends string, Path extends string> = PatternMatches<Rest, Path> extends true ? true : Path extends `${infer PathHead}/${infer PathRest}` ? PathHead extends "" ? false : PatternMatches<Rest, PathRest> : false;
|
|
19
|
+
/**
|
|
20
|
+
* Mirrors the router: `:param` matches one non-empty segment, `:param?` one
|
|
21
|
+
* or none, `*` the rest. `Head` is always a single segment: `${infer Head}/`
|
|
22
|
+
* stops at the first slash.
|
|
23
|
+
*/
|
|
24
|
+
type PatternMatches<Pattern extends string, Path extends string> = Pattern extends "*" ? true : Pattern extends `${infer Head}/${infer Rest}` ? Head extends `:${string}?` ? OptionalSegmentMatches<Rest, Path> : Path extends `${infer PathHead}/${infer PathRest}` ? SegmentMatches<Head, PathHead> extends true ? PatternMatches<Rest, PathRest> : false : Rest extends `${string}/${string}` ? false : Rest extends `:${string}?` ? SegmentMatches<Head, Path> : false : Pattern extends `:${string}?` ? Path extends `${string}/${string}` ? false : true : Path extends `${string}/${string}` ? false : SegmentMatches<Pattern, Path>;
|
|
19
25
|
type MatchingPattern<Path extends string> = {
|
|
20
26
|
[Pattern in RoutePattern]: PatternMatches<Pattern, Path> extends true ? Pattern : never;
|
|
21
27
|
}[RoutePattern];
|
|
@@ -87,7 +93,7 @@ export type RouteParamsOf<To extends RouteTo> = keyof RouteManifest extends neve
|
|
|
87
93
|
[Key in keyof Params]: RouteParamInput<Params[Key]>;
|
|
88
94
|
} : undefined : undefined;
|
|
89
95
|
export type PreloadStrategy = false | "intent" | "viewport" | "render";
|
|
90
|
-
type LinkPathParamKeys<Path extends string> = Path extends `${infer Segment}/${infer Rest}` ? LinkPathParamKeys<Segment> | LinkPathParamKeys<Rest> : Path extends `:${infer Key}` ? Key : Path extends "*" ? "
|
|
96
|
+
type LinkPathParamKeys<Path extends string> = Path extends `${infer Segment}/${infer Rest}` ? LinkPathParamKeys<Segment> | LinkPathParamKeys<Rest> : Path extends `:${string}?` ? never : Path extends `:${infer Key}` ? Key : Path extends "*" ? "_splat" : never;
|
|
91
97
|
type LinkParams<To extends RouteTo> = [To] extends [RoutePattern] ? LinkPathParamKeys<To> extends never ? {
|
|
92
98
|
params?: RouteParamsOf<To>;
|
|
93
99
|
} : {
|
package/dist/client.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
useQuery2,
|
|
12
12
|
getRouteApi2,
|
|
13
13
|
createSyncCatchUp
|
|
14
|
-
} from "./client/chunks/client-
|
|
14
|
+
} from "./client/chunks/client-d9v49jwz.js";
|
|
15
15
|
|
|
16
16
|
// src/client/client-module.ts
|
|
17
17
|
import { preloadModule } from "react-dom";
|
|
@@ -37,35 +37,51 @@ function preloadClientModule(mod) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
// src/client/define-route.ts
|
|
40
|
-
function createRouteBuilder(
|
|
40
|
+
function createRouteBuilder(state) {
|
|
41
|
+
const { errorComponent, notFoundComponent, remountDeps } = state;
|
|
41
42
|
return {
|
|
42
43
|
config(options) {
|
|
43
|
-
return createRouteBuilder(options.remountDeps);
|
|
44
|
+
return createRouteBuilder({ ...state, remountDeps: options.remountDeps });
|
|
45
|
+
},
|
|
46
|
+
error(component) {
|
|
47
|
+
return createRouteBuilder({ ...state, errorComponent: component });
|
|
44
48
|
},
|
|
45
49
|
layout(component) {
|
|
46
50
|
const runtimeComponent = component;
|
|
47
51
|
return {
|
|
48
52
|
__type: "FURIN_ROUTE",
|
|
49
53
|
component: runtimeComponent,
|
|
50
|
-
|
|
54
|
+
errorComponent,
|
|
55
|
+
layout: runtimeComponent,
|
|
56
|
+
notFoundComponent
|
|
51
57
|
};
|
|
52
58
|
},
|
|
59
|
+
notFound(component) {
|
|
60
|
+
return createRouteBuilder({ ...state, notFoundComponent: component });
|
|
61
|
+
},
|
|
53
62
|
page(component) {
|
|
54
63
|
const runtimeComponent = component;
|
|
55
64
|
return {
|
|
56
65
|
__type: "FURIN_ROUTE",
|
|
57
66
|
component: runtimeComponent,
|
|
67
|
+
errorComponent,
|
|
68
|
+
notFoundComponent,
|
|
58
69
|
page: runtimeComponent,
|
|
59
70
|
remountDeps
|
|
60
71
|
};
|
|
61
72
|
}
|
|
62
73
|
};
|
|
63
74
|
}
|
|
75
|
+
var EMPTY_BUILDER = {
|
|
76
|
+
errorComponent: undefined,
|
|
77
|
+
notFoundComponent: undefined,
|
|
78
|
+
remountDeps: undefined
|
|
79
|
+
};
|
|
64
80
|
function defineRoute(_id) {
|
|
65
|
-
return createRouteBuilder(
|
|
81
|
+
return createRouteBuilder(EMPTY_BUILDER);
|
|
66
82
|
}
|
|
67
83
|
function defineRootRoute() {
|
|
68
|
-
return createRouteBuilder(
|
|
84
|
+
return createRouteBuilder(EMPTY_BUILDER);
|
|
69
85
|
}
|
|
70
86
|
// src/client/hmr.ts
|
|
71
87
|
import { jsx } from "react/jsx-runtime";
|
package/dist/config.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare const configSchema: import("typebox").TObject<{
|
|
|
38
38
|
apps: import("typebox").TOptional<import("typebox").TArray<import("typebox").TObject<{
|
|
39
39
|
pagesDir: import("typebox").TString;
|
|
40
40
|
prefix: import("typebox").TOptional<import("typebox").TString>;
|
|
41
|
+
style: import("typebox").TUnion<[import("typebox").TLiteral<"nextjs">, import("typebox").TLiteral<"tanstack">]>;
|
|
41
42
|
}>>>;
|
|
42
43
|
bun: import("typebox").TOptional<import("typebox").TObject<{
|
|
43
44
|
compile: import("typebox").TOptional<import("typebox").TUnion<[import("typebox").TLiteral<"server">, import("typebox").TLiteral<"embed">]>>;
|
|
@@ -57,6 +58,7 @@ export declare const configSchema: import("typebox").TObject<{
|
|
|
57
58
|
* Packages declaring `sideEffects: false` are optimized automatically.
|
|
58
59
|
*/
|
|
59
60
|
optimizeImports: import("typebox").TOptional<import("typebox").TArray<import("typebox").TString>>;
|
|
61
|
+
/** Single-app build: its pages directory, with `style`. Prefer `apps` or the server entry's mounts. */
|
|
60
62
|
pagesDir: import("typebox").TOptional<import("typebox").TString>;
|
|
61
63
|
/**
|
|
62
64
|
* Module preloading. `routeChunks` (default true) makes `<HeadContent />`
|
|
@@ -74,6 +76,8 @@ export declare const configSchema: import("typebox").TObject<{
|
|
|
74
76
|
serverEntry: import("typebox").TOptional<import("typebox").TString>;
|
|
75
77
|
/** Emit private server source maps for error-tool uploads. Off by default. */
|
|
76
78
|
serverSourceMaps: import("typebox").TOptional<import("typebox").TBoolean>;
|
|
79
|
+
/** File-routing style of `pagesDir`: `"nextjs"` or `"tanstack"`. */
|
|
80
|
+
style: import("typebox").TOptional<import("typebox").TUnion<[import("typebox").TLiteral<"nextjs">, import("typebox").TLiteral<"tanstack">]>>;
|
|
77
81
|
static: import("typebox").TOptional<import("typebox").TObject<{
|
|
78
82
|
basePath: import("typebox").TOptional<import("typebox").TString>;
|
|
79
83
|
onSSR: import("typebox").TOptional<import("typebox").TUnion<[import("typebox").TLiteral<"error">, import("typebox").TLiteral<"skip">]>>;
|
package/dist/config.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
import { t } from "elysia";
|
|
4
4
|
var BUILD_TARGETS = ["bun", "vercel", "static", "package"];
|
|
5
5
|
var compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
|
|
6
|
+
var routeStyleSchema = t.Union([t.Literal("nextjs"), t.Literal("tanstack")]);
|
|
6
7
|
var configSchema = t.Object({
|
|
7
8
|
apps: t.Optional(t.Array(t.Object({
|
|
8
9
|
pagesDir: t.String(),
|
|
9
|
-
prefix: t.Optional(t.String())
|
|
10
|
+
prefix: t.Optional(t.String()),
|
|
11
|
+
style: routeStyleSchema
|
|
10
12
|
}))),
|
|
11
13
|
bun: t.Optional(t.Object({
|
|
12
14
|
compile: t.Optional(compileTargetSchema),
|
|
@@ -21,6 +23,7 @@ var configSchema = t.Object({
|
|
|
21
23
|
rootDir: t.Optional(t.String()),
|
|
22
24
|
serverEntry: t.Optional(t.String()),
|
|
23
25
|
serverSourceMaps: t.Optional(t.Boolean()),
|
|
26
|
+
style: t.Optional(routeStyleSchema),
|
|
24
27
|
static: t.Optional(t.Object({
|
|
25
28
|
basePath: t.Optional(t.String()),
|
|
26
29
|
onSSR: t.Optional(t.Union([t.Literal("error"), t.Literal("skip")])),
|
package/dist/define-route.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { type Context, Elysia } from "elysia";
|
|
|
3
3
|
import type { RequestLogger } from "evlog";
|
|
4
4
|
import type { HeadOptions, RenderingMode } from "./client.ts";
|
|
5
5
|
import type { FurinSchema, FurinUnwrap, FurinUnwrapInput } from "./shared/elysia-contract.ts";
|
|
6
|
+
import type { ErrorComponent } from "./shared/error.ts";
|
|
7
|
+
import type { NotFoundComponent } from "./shared/not-found.ts";
|
|
6
8
|
import type { RemountDependency, RemountDeps } from "./shared/page-key.ts";
|
|
7
9
|
type NoFields = NonNullable<unknown>;
|
|
8
10
|
type Awaitable<T> = Promise<T> | T;
|
|
@@ -181,27 +183,49 @@ type LayoutComponent<Params, Query, ParentData extends LoaderData, Data extends
|
|
|
181
183
|
}) => React.ReactNode;
|
|
182
184
|
type Head<Params, Query, ParentData extends LoaderData, Data extends LoaderData, Mode extends RenderingMode> = (context: RenderContext<Params, Query, Mode extends "ssr" ? SsrParentData<ParentData> : PublicParentData<ParentData>, Data, NoFields>) => HeadOptions;
|
|
183
185
|
export declare function getFurinRenderer(context: object): FurinRouteDispatcher | undefined;
|
|
186
|
+
interface ElysiaPathParams {
|
|
187
|
+
[name: string]: string | undefined;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Elysia names a catch-all `*`; routes read it as `_splat`, as in TanStack
|
|
191
|
+
* Start. A transform hook runs before validation, so params schemas see it.
|
|
192
|
+
*/
|
|
193
|
+
declare function renameSplatParam(context: {
|
|
194
|
+
params: ElysiaPathParams | undefined;
|
|
195
|
+
}): void;
|
|
184
196
|
declare function registerPlain(route: FurinRouteKey): import("elysia/types").AddRoute<"", "local", import("elysia").DefaultSingleton, {
|
|
185
197
|
typebox: {};
|
|
186
198
|
error: [];
|
|
187
|
-
}, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, "get", "", import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<
|
|
199
|
+
}, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, "get", "", import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<import("elysia").InputSchema<never> & {
|
|
200
|
+
beforeHandle?: unknown;
|
|
201
|
+
afterHandle?: unknown;
|
|
202
|
+
error?: unknown;
|
|
203
|
+
}, {}, "">, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>, {}, (context: object) => unknown, import("elysia").InputSchema<never> & {
|
|
204
|
+
beforeHandle?: unknown;
|
|
205
|
+
afterHandle?: unknown;
|
|
206
|
+
error?: unknown;
|
|
207
|
+
}>;
|
|
188
208
|
declare function registerSchema<ParamsSchema extends FurinSchema, QuerySchema extends FurinSchema | undefined>(route: FurinRouteKey, paramsSchema: ParamsSchema, querySchema: QuerySchema): import("elysia/types").AddRoute<"", "local", import("elysia").DefaultSingleton, {
|
|
189
209
|
typebox: {};
|
|
190
210
|
error: [];
|
|
191
211
|
}, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, "get", "", import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{
|
|
192
212
|
params: ParamsSchema;
|
|
193
213
|
query: QuerySchema;
|
|
214
|
+
transform: typeof renameSplatParam;
|
|
194
215
|
}, {}, "">, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>, {}, (context: object) => unknown, {
|
|
195
216
|
params: ParamsSchema;
|
|
196
217
|
query: QuerySchema;
|
|
218
|
+
transform: typeof renameSplatParam;
|
|
197
219
|
}>;
|
|
198
220
|
declare function registerQuery<QuerySchema extends FurinSchema>(route: FurinRouteKey, querySchema: QuerySchema): import("elysia/types").AddRoute<"", "local", import("elysia").DefaultSingleton, {
|
|
199
221
|
typebox: {};
|
|
200
222
|
error: [];
|
|
201
223
|
}, import("elysia").DefaultMetadata, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral, "get", "", import("elysia/types").IntersectIfObjectSchema<import("elysia").UnwrapRoute<{
|
|
202
224
|
query: QuerySchema;
|
|
225
|
+
transform: typeof renameSplatParam;
|
|
203
226
|
}, {}, "">, import("elysia/types").MergeScopedSchemas<{}, {}, {}>>, {}, (context: object) => unknown, {
|
|
204
227
|
query: QuerySchema;
|
|
228
|
+
transform: typeof renameSplatParam;
|
|
205
229
|
}>;
|
|
206
230
|
declare function registerLayout(paramsSchema: FurinSchema | undefined, querySchema: FurinSchema | undefined): Elysia<"", "local", import("elysia").DefaultSingleton, {
|
|
207
231
|
typebox: {};
|
|
@@ -306,26 +330,34 @@ interface NoLayoutOption {
|
|
|
306
330
|
layout?: FurinTypeError<"defineRoute(id) reads the parent layout from the pages tree: remove layout">;
|
|
307
331
|
}
|
|
308
332
|
/** A terminal the route file's kind does not allow becomes a compile error. */
|
|
309
|
-
type KindCheck<State extends ChainState, Terminal extends RouteKind, ValidComponent> = Terminal extends State["kind"] ? ValidComponent : FurinTypeError<Terminal extends "page" ? "this route file is a layout
|
|
333
|
+
type KindCheck<State extends ChainState, Terminal extends RouteKind, ValidComponent> = Terminal extends State["kind"] ? ValidComponent : FurinTypeError<Terminal extends "page" ? "this route file is a layout: finish it with layout()" : "this route file is a page: finish it with page()">;
|
|
310
334
|
interface ChainRuntime {
|
|
335
|
+
errorComponent: ErrorComponent | undefined;
|
|
311
336
|
head: unknown;
|
|
312
337
|
loader: unknown;
|
|
313
338
|
metadata: RouteMetadata;
|
|
339
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
314
340
|
paramsSchema: FurinSchema | undefined;
|
|
315
341
|
querySchema: FurinSchema | undefined;
|
|
316
342
|
requestLoader: unknown;
|
|
317
343
|
}
|
|
344
|
+
/** `.error()` / `.notFound()` keep the stage they are called on. */
|
|
345
|
+
type BoundaryMethods = "error" | "notFound";
|
|
346
|
+
interface BoundaryStage<Stage> {
|
|
347
|
+
error: (component: ErrorComponent) => Stage;
|
|
348
|
+
notFound: (component: NotFoundComponent) => Stage;
|
|
349
|
+
}
|
|
318
350
|
/** SSR routes render per request: `staticParams()` needs mode `ssg` or `isr`. */
|
|
319
|
-
interface SsrRouteStage<State extends ChainState> extends Omit<RouteChain<State>, "staticParams"
|
|
351
|
+
interface SsrRouteStage<State extends ChainState> extends Omit<RouteChain<State>, "staticParams" | BoundaryMethods>, BoundaryStage<SsrRouteStage<State>> {
|
|
320
352
|
}
|
|
321
353
|
/** `staticParams()` must come first and only once, before `requestLoader()`. */
|
|
322
|
-
interface StaticParamsClosedStage<State extends ChainState> extends Omit<RouteChain<State>, "staticParams"
|
|
354
|
+
interface StaticParamsClosedStage<State extends ChainState> extends Omit<RouteChain<State>, "staticParams" | BoundaryMethods>, BoundaryStage<StaticParamsClosedStage<State>> {
|
|
323
355
|
}
|
|
324
356
|
/** After `loader()`: attach `head()` or finish with `page()`/`layout()`. */
|
|
325
|
-
interface LoadedRouteStage<State extends ChainState> extends Pick<RouteChain<State>, "head" | "layout" | "page"
|
|
357
|
+
interface LoadedRouteStage<State extends ChainState> extends Pick<RouteChain<State>, "head" | "layout" | "page">, BoundaryStage<LoadedRouteStage<State>> {
|
|
326
358
|
}
|
|
327
359
|
/** `head()` metadata is page-only: a headed route can only finish with `page()`. */
|
|
328
|
-
interface HeadedPageStage<State extends ChainState> extends Pick<RouteChain<State>, "page"
|
|
360
|
+
interface HeadedPageStage<State extends ChainState> extends Pick<RouteChain<State>, "page">, BoundaryStage<HeadedPageStage<State>> {
|
|
329
361
|
}
|
|
330
362
|
type ConfiguredStage<State extends ChainState> = State["mode"] extends infer Mode ? Mode extends "ssr" ? SsrRouteStage<State> : RouteChain<State> : never;
|
|
331
363
|
type ElysiaOfSchemas<Schemas> = Schemas extends {
|
|
@@ -336,6 +368,8 @@ type ElysiaOfSchemas<Schemas> = Schemas extends {
|
|
|
336
368
|
} ? ReturnType<typeof registerQuery<QuerySchema>> : ReturnType<typeof registerPlain>;
|
|
337
369
|
type RouteTerminal<State extends ChainState> = {
|
|
338
370
|
__type: "FURIN_ROUTE";
|
|
371
|
+
errorComponent: ErrorComponent | undefined;
|
|
372
|
+
notFoundComponent: NotFoundComponent | undefined;
|
|
339
373
|
head: Head<State["params"], State["query"], State["parentData"], State["data"], State["mode"]> | undefined;
|
|
340
374
|
mode: State["mode"];
|
|
341
375
|
readonly [inheritedDataBrand]?: State["parentData"];
|
|
@@ -370,6 +404,13 @@ type LayoutTerminal<State extends ChainState> = RouteTerminal<State> & {
|
|
|
370
404
|
declare class RouteChain<State extends ChainState> {
|
|
371
405
|
protected readonly runtime: ChainRuntime;
|
|
372
406
|
constructor(runtime: ChainRuntime);
|
|
407
|
+
/**
|
|
408
|
+
* TanStack style: renders in place of this route (in its parent's outlet)
|
|
409
|
+
* when it or a route below it fails, as `errorComponent` does.
|
|
410
|
+
*/
|
|
411
|
+
error(component: ErrorComponent): this;
|
|
412
|
+
/** TanStack style: renders when this route or one below it calls `notFound()`. */
|
|
413
|
+
notFound(component: NotFoundComponent): this;
|
|
373
414
|
requestLoader<Data extends RequestLoaderData>(requestLoader: RequestLoader<State["params"], State["query"], Data>): StaticParamsClosedStage<WithState<State, {
|
|
374
415
|
requestData: Data;
|
|
375
416
|
}>>;
|
|
@@ -384,7 +425,7 @@ declare class RouteChain<State extends ChainState> {
|
|
|
384
425
|
layout(component: KindCheck<State, "layout", LayoutComponentOf<State>>): LayoutTerminal<State>;
|
|
385
426
|
}
|
|
386
427
|
/**
|
|
387
|
-
* Stage for
|
|
428
|
+
* Stage for the root layout — the document shell has no layout above it, so
|
|
388
429
|
* `config()` requires only `mode` (the TanStack `createRootRoute` analogue).
|
|
389
430
|
*/
|
|
390
431
|
declare class UnconfiguredRootRoute {
|
|
@@ -418,10 +459,10 @@ declare class UnconfiguredRootRoute {
|
|
|
418
459
|
}): ConfiguredRoute<EmptyContract, NoFields, undefined, undefined, undefined, Mode>;
|
|
419
460
|
}
|
|
420
461
|
/**
|
|
421
|
-
* First stage of the builder, `defineRoute("/board/
|
|
462
|
+
* First stage of the builder, `defineRoute("/board/$boardId/")`: `config()` is
|
|
422
463
|
* MANDATORY and declares at least `mode`. The generated `FileRoutes` entry
|
|
423
464
|
* supplies the parent layout, the path params and the terminal (`layout()` for
|
|
424
|
-
*
|
|
465
|
+
* layout files, `page()` otherwise), so `config()` takes no `layout` and
|
|
425
466
|
* `params` only refines the path params.
|
|
426
467
|
*/
|
|
427
468
|
declare class UnconfiguredFileRoute<Entry> {
|
|
@@ -455,9 +496,9 @@ declare class UnconfiguredFileRoute<Entry> {
|
|
|
455
496
|
}): FileConfiguredRoute<Entry, undefined, undefined, undefined, Mode>;
|
|
456
497
|
}
|
|
457
498
|
/**
|
|
458
|
-
* `defineRoute(id)` keys the route by its
|
|
459
|
-
*
|
|
460
|
-
*
|
|
499
|
+
* `defineRoute(id)` keys the route by its TanStack Start id (the app's
|
|
500
|
+
* prefix, then `/board/$boardId/` for an index, `/board` for a layout, in
|
|
501
|
+
* both routing styles) and reads its parent from the generated `FileRoutes`.
|
|
461
502
|
* The id is type-only: the runtime chain comes from the pages tree.
|
|
462
503
|
*/
|
|
463
504
|
export declare function defineRoute<Id extends FileRouteId>(_id: Id): UnconfiguredFileRoute<FileRouteOf<Id>>;
|