@teyik0/furin 0.9.0-alpha.1 → 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/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/index.js +594 -422
- 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 +3 -3
- 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 +766 -614
- 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 +57 -76
- package/dist/server/registrations.d.ts +4 -2
- 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 +88 -120
- package/dist/server/sync/drizzle/index.d.ts +8 -10
- package/dist/shared/route-specificity.d.ts +10 -1
- package/package.json +3 -6
- 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/index.ts +30 -14
- package/src/client/define-route.ts +29 -4
- package/src/client/internal/runtime-types.ts +8 -0
- package/src/client/router/link-utils.ts +16 -8
- 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/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/route-specificity.ts +34 -2
- package/src/shared/utils/index.ts +1 -1
|
@@ -147,7 +147,7 @@ function segmentSpecificity(segment) {
|
|
|
147
147
|
}
|
|
148
148
|
return segment.startsWith(":") ? 2 : 3;
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function compareConcreteSpecificity(a, b) {
|
|
151
151
|
const aSegments = a.split("/").filter(Boolean);
|
|
152
152
|
const bSegments = b.split("/").filter(Boolean);
|
|
153
153
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
@@ -167,6 +167,24 @@ function compareRouteSpecificity(a, b) {
|
|
|
167
167
|
}
|
|
168
168
|
return 0;
|
|
169
169
|
}
|
|
170
|
+
function expandOptionalSegments(pattern) {
|
|
171
|
+
let variants = [[]];
|
|
172
|
+
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
173
|
+
if (segment.startsWith(":") && segment.endsWith("?")) {
|
|
174
|
+
const required = segment.slice(0, -1);
|
|
175
|
+
variants = variants.flatMap((variant) => [variant, [...variant, required]]);
|
|
176
|
+
} else {
|
|
177
|
+
variants = variants.map((variant) => [...variant, segment]);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return variants.map((variant) => `/${variant.join("/")}`);
|
|
181
|
+
}
|
|
182
|
+
function mostSpecificVariant(pattern) {
|
|
183
|
+
return expandOptionalSegments(pattern).reduce((best, variant) => compareConcreteSpecificity(variant, best) > 0 ? variant : best);
|
|
184
|
+
}
|
|
185
|
+
function compareRouteSpecificity(a, b) {
|
|
186
|
+
return compareConcreteSpecificity(mostSpecificVariant(a), mostSpecificVariant(b));
|
|
187
|
+
}
|
|
170
188
|
|
|
171
189
|
// src/shared/search-params.ts
|
|
172
190
|
function isObject(value) {
|
|
@@ -3170,11 +3188,12 @@ function navigationHrefPolicy(href, currentOrigin) {
|
|
|
3170
3188
|
return url.origin === currentOrigin ? "internal" : "external";
|
|
3171
3189
|
}
|
|
3172
3190
|
function applyLinkParams(to, params) {
|
|
3173
|
-
|
|
3174
|
-
|
|
3191
|
+
const values = params ?? {};
|
|
3192
|
+
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);
|
|
3193
|
+
if (url === "") {
|
|
3194
|
+
url = "/";
|
|
3175
3195
|
}
|
|
3176
|
-
|
|
3177
|
-
const wildcard = params["*"];
|
|
3196
|
+
const wildcard = values._splat;
|
|
3178
3197
|
if (wildcard !== undefined && url.includes("/*")) {
|
|
3179
3198
|
const encodedWildcard = String(wildcard).split("/").map(encodeURIComponent).join("/");
|
|
3180
3199
|
url = url.replace("/*", () => `/${encodedWildcard}`);
|
|
@@ -3654,51 +3673,9 @@ var init_graph = __esm(() => {
|
|
|
3654
3673
|
});
|
|
3655
3674
|
|
|
3656
3675
|
// src/server/router/patterns.ts
|
|
3657
|
-
import { parse } from "path";
|
|
3658
3676
|
function resolveRouteRevalidate(page) {
|
|
3659
3677
|
return page.revalidate ?? page._route.revalidate;
|
|
3660
3678
|
}
|
|
3661
|
-
function parseDynamicRouteSegment(segment, sourcePath) {
|
|
3662
|
-
if (!(segment.startsWith("[") && segment.endsWith("]"))) {
|
|
3663
|
-
return;
|
|
3664
|
-
}
|
|
3665
|
-
const inner = segment.slice(1, -1);
|
|
3666
|
-
const catchAll = inner.startsWith("...");
|
|
3667
|
-
const name = catchAll ? inner.slice(3) : inner;
|
|
3668
|
-
if (!DYNAMIC_PARAMETER_NAME_RE.test(name)) {
|
|
3669
|
-
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(name)} in ${JSON.stringify(sourcePath ?? segment)}. Parameter names must match ${DYNAMIC_PARAMETER_NAME_RE}.`);
|
|
3670
|
-
}
|
|
3671
|
-
return { catchAll, name };
|
|
3672
|
-
}
|
|
3673
|
-
function isRouteGroup(segment) {
|
|
3674
|
-
return ROUTE_GROUP_RE.test(segment);
|
|
3675
|
-
}
|
|
3676
|
-
function filePathToPattern(path) {
|
|
3677
|
-
const parts = path.replaceAll("\\", "/").split("/");
|
|
3678
|
-
const segments = [];
|
|
3679
|
-
const lastIndex = parts.length - 1;
|
|
3680
|
-
for (let idx = 0;idx < parts.length; idx += 1) {
|
|
3681
|
-
const part = parts[idx];
|
|
3682
|
-
if (part === undefined || part.length === 0) {
|
|
3683
|
-
continue;
|
|
3684
|
-
}
|
|
3685
|
-
const isFile = idx === lastIndex;
|
|
3686
|
-
const name = isFile ? parse(part).name : part;
|
|
3687
|
-
if (!isFile && isRouteGroup(name)) {
|
|
3688
|
-
continue;
|
|
3689
|
-
}
|
|
3690
|
-
if (isFile && name === "index") {
|
|
3691
|
-
continue;
|
|
3692
|
-
}
|
|
3693
|
-
const dynamic = parseDynamicRouteSegment(name, path);
|
|
3694
|
-
if (dynamic) {
|
|
3695
|
-
segments.push(dynamic.catchAll ? "*" : `:${dynamic.name}`);
|
|
3696
|
-
} else {
|
|
3697
|
-
segments.push(name);
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
return `/${segments.join("/")}`;
|
|
3701
|
-
}
|
|
3702
3679
|
function escapeRegExp(value) {
|
|
3703
3680
|
return value.replace(REGEX_META_CHARS_RE, "\\$&");
|
|
3704
3681
|
}
|
|
@@ -3713,11 +3690,17 @@ function routePatternRegexSource(pattern, sources) {
|
|
|
3713
3690
|
while (i < pattern.length && pattern[i] !== "/") {
|
|
3714
3691
|
i += 1;
|
|
3715
3692
|
}
|
|
3716
|
-
|
|
3717
|
-
|
|
3693
|
+
const name = pattern.slice(start, i);
|
|
3694
|
+
if (name.endsWith("?") && source.endsWith("/")) {
|
|
3695
|
+
paramNames.push(name.slice(0, -1));
|
|
3696
|
+
source = `${source.slice(0, -1)}(?:/${sources.param})?`;
|
|
3697
|
+
} else {
|
|
3698
|
+
paramNames.push(name);
|
|
3699
|
+
source += sources.param;
|
|
3700
|
+
}
|
|
3718
3701
|
} else if (pattern[i] === "*") {
|
|
3719
|
-
paramNames.push(
|
|
3720
|
-
source
|
|
3702
|
+
paramNames.push(SPLAT_PARAM);
|
|
3703
|
+
source = source.endsWith("/") ? `${source.slice(0, -1)}(?:/${sources.catchAll})?` : source + sources.catchAll;
|
|
3721
3704
|
i += 1;
|
|
3722
3705
|
} else {
|
|
3723
3706
|
const ch = pattern[i];
|
|
@@ -3739,6 +3722,25 @@ function buildRouteRegex(pattern) {
|
|
|
3739
3722
|
regex: new RegExp(`^${source}${pattern === "/" || pattern.endsWith("/") ? "" : "/?"}$`)
|
|
3740
3723
|
};
|
|
3741
3724
|
}
|
|
3725
|
+
function decodeParam(value) {
|
|
3726
|
+
try {
|
|
3727
|
+
return decodeURIComponent(value);
|
|
3728
|
+
} catch {
|
|
3729
|
+
return value;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
function matchedParams(paramNames, match) {
|
|
3733
|
+
const params = {};
|
|
3734
|
+
for (const [index, name] of paramNames.entries()) {
|
|
3735
|
+
const value = match[index + 1];
|
|
3736
|
+
if (value !== undefined) {
|
|
3737
|
+
params[name] = decodeParam(value);
|
|
3738
|
+
} else if (name === SPLAT_PARAM) {
|
|
3739
|
+
params[name] = "";
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
return params;
|
|
3743
|
+
}
|
|
3742
3744
|
function buildRouteMatcher(routes) {
|
|
3743
3745
|
const compiled = routes.map((route) => {
|
|
3744
3746
|
const { regex, paramNames } = buildRouteRegex(route.pattern);
|
|
@@ -3750,26 +3752,13 @@ function buildRouteMatcher(routes) {
|
|
|
3750
3752
|
if (!match) {
|
|
3751
3753
|
continue;
|
|
3752
3754
|
}
|
|
3753
|
-
|
|
3754
|
-
for (let i = 0;i < candidate.paramNames.length; i += 1) {
|
|
3755
|
-
const name = candidate.paramNames[i];
|
|
3756
|
-
if (name !== undefined) {
|
|
3757
|
-
try {
|
|
3758
|
-
params[name] = decodeURIComponent(match[i + 1] ?? "");
|
|
3759
|
-
} catch {
|
|
3760
|
-
params[name] = match[i + 1] ?? "";
|
|
3761
|
-
}
|
|
3762
|
-
}
|
|
3763
|
-
}
|
|
3764
|
-
return { params, route: candidate.route };
|
|
3755
|
+
return { params: matchedParams(candidate.paramNames, match), route: candidate.route };
|
|
3765
3756
|
}
|
|
3766
3757
|
return null;
|
|
3767
3758
|
};
|
|
3768
3759
|
}
|
|
3769
|
-
var
|
|
3760
|
+
var SPLAT_PARAM = "_splat", REGEX_META_CHARS_RE;
|
|
3770
3761
|
var init_patterns = __esm(() => {
|
|
3771
|
-
DYNAMIC_PARAMETER_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
3772
|
-
ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
3773
3762
|
REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
3774
3763
|
});
|
|
3775
3764
|
|
|
@@ -4123,7 +4112,7 @@ function validateRouteChain(chain, root, pagePath) {
|
|
|
4123
4112
|
const hasRoot = chain.some((r) => r === root);
|
|
4124
4113
|
if (!hasRoot) {
|
|
4125
4114
|
const location = pagePath ? `in ${pagePath}` : "";
|
|
4126
|
-
throw new Error(`[furin] Page ${location} must inherit from root route. ` + "Its route chain must end at the root
|
|
4115
|
+
throw new Error(`[furin] Page ${location} must inherit from root route. ` + "Its route chain must end at the root layout.");
|
|
4127
4116
|
}
|
|
4128
4117
|
for (const route of chain) {
|
|
4129
4118
|
if (hasCycle(route)) {
|
|
@@ -10347,8 +10336,6 @@ function renderForPath(route, params, root, origin, mode, basePath, searchRoutes
|
|
|
10347
10336
|
}
|
|
10348
10337
|
|
|
10349
10338
|
// src/server/render/static-params.ts
|
|
10350
|
-
import { dirname as dirname2, relative } from "path";
|
|
10351
|
-
init_patterns();
|
|
10352
10339
|
var STATIC_PARAMS_CONCURRENCY = 4;
|
|
10353
10340
|
var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
10354
10341
|
function collectStaticParamsStages(route) {
|
|
@@ -10364,17 +10351,11 @@ function collectStaticParamsStages(route) {
|
|
|
10364
10351
|
return stages;
|
|
10365
10352
|
}
|
|
10366
10353
|
function ancestorPattern(route, ancestors) {
|
|
10367
|
-
const rootSourcePath = route.routeChain[0]?.sourcePath;
|
|
10368
10354
|
const ancestorSourcePath = ancestors.at(-1)?.sourcePath;
|
|
10369
|
-
if (
|
|
10370
|
-
return route.pattern;
|
|
10371
|
-
}
|
|
10372
|
-
const pagesDir = dirname2(rootSourcePath);
|
|
10373
|
-
const ancestorDir = dirname2(ancestorSourcePath);
|
|
10374
|
-
if (ancestorDir === pagesDir) {
|
|
10355
|
+
if (ancestors.length <= 1) {
|
|
10375
10356
|
return "/";
|
|
10376
10357
|
}
|
|
10377
|
-
return
|
|
10358
|
+
return route.layouts.find(({ path }) => path === ancestorSourcePath)?.pattern ?? route.pattern;
|
|
10378
10359
|
}
|
|
10379
10360
|
function createBuildContext(pattern, params, origin) {
|
|
10380
10361
|
const path = resolvePath(pattern, params);
|
|
@@ -10560,9 +10541,11 @@ function adaptDefinedLayout(route, parent, sourcePath) {
|
|
|
10560
10541
|
const component = route.component;
|
|
10561
10542
|
return {
|
|
10562
10543
|
__type: "FURIN_ROUTE",
|
|
10544
|
+
errorComponent: route.errorComponent,
|
|
10563
10545
|
layout: component,
|
|
10564
10546
|
loader: route.loader,
|
|
10565
10547
|
mode: route.mode,
|
|
10548
|
+
notFoundComponent: route.notFoundComponent,
|
|
10566
10549
|
params: route.schemas?.params,
|
|
10567
10550
|
...parent ? { parent } : {},
|
|
10568
10551
|
query: route.schemas?.query,
|
|
@@ -10587,9 +10570,11 @@ function adaptDefinedPage(route, parent) {
|
|
|
10587
10570
|
requestLoader: route.requestLoader
|
|
10588
10571
|
},
|
|
10589
10572
|
component,
|
|
10573
|
+
errorComponent: route.errorComponent,
|
|
10590
10574
|
head,
|
|
10591
10575
|
loader: route.loader,
|
|
10592
10576
|
mode: route.mode,
|
|
10577
|
+
notFoundComponent: route.notFoundComponent,
|
|
10593
10578
|
revalidate: route.revalidate,
|
|
10594
10579
|
staticParams: route.staticParams,
|
|
10595
10580
|
tags: copyTags(route.tags)
|
|
@@ -10612,7 +10597,7 @@ function collectRouteTags(routeChain, page) {
|
|
|
10612
10597
|
function loadProdRoutes(ctx) {
|
|
10613
10598
|
const rootExport = ctx.modules[ctx.rootPath]?.route;
|
|
10614
10599
|
if (!isDefinedRouteTerminal(rootExport) || typeof rootExport.layout !== "function") {
|
|
10615
|
-
throw new Error(
|
|
10600
|
+
throw new Error(`[furin] ${ctx.rootPath}: defineRootRoute().layout() not found in CompileContext.`);
|
|
10616
10601
|
}
|
|
10617
10602
|
const rootRoute = adaptDefinedLayout(rootExport, undefined, ctx.rootPath);
|
|
10618
10603
|
function resolveModuleComponent(modPath) {
|
|
@@ -10622,26 +10607,28 @@ function loadProdRoutes(ctx) {
|
|
|
10622
10607
|
return ctx.modules[modPath]?.default;
|
|
10623
10608
|
}
|
|
10624
10609
|
const root = {
|
|
10625
|
-
error: resolveModuleComponent(ctx.rootConventions?.errorPath),
|
|
10626
|
-
notFound: resolveModuleComponent(ctx.rootConventions?.notFoundPath),
|
|
10610
|
+
error: rootRoute.errorComponent ?? resolveModuleComponent(ctx.rootConventions?.errorPath),
|
|
10611
|
+
notFound: rootRoute.notFoundComponent ?? resolveModuleComponent(ctx.rootConventions?.notFoundPath),
|
|
10627
10612
|
path: ctx.rootPath,
|
|
10628
10613
|
route: rootRoute
|
|
10629
10614
|
};
|
|
10630
10615
|
const routes = [];
|
|
10631
10616
|
for (const { pattern, path, mode } of ctx.routes) {
|
|
10632
|
-
const
|
|
10617
|
+
const meta = ctx.routeMetadata?.[path];
|
|
10618
|
+
const layouts = meta?.layouts ?? [];
|
|
10619
|
+
const page = resolveCompiledRuntimePage(ctx.modules[path] ?? {}, layouts, root, ctx);
|
|
10633
10620
|
if (!page) {
|
|
10634
10621
|
throw new Error(`[furin] ${path}: invalid page module in CompileContext.`);
|
|
10635
10622
|
}
|
|
10636
10623
|
const routeChain = collectRouteChainFromRoute(page._route);
|
|
10637
10624
|
validateRouteChain(routeChain, root.route, path);
|
|
10638
|
-
const
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
notFound: resolveModuleComponent(b.notFoundPath)
|
|
10625
|
+
const boundaries = (meta?.segmentBoundaries ?? []).map((boundary) => ({
|
|
10626
|
+
...boundary,
|
|
10627
|
+
error: boundary.fromRoute ? routeBoundaryComponent(ctx, boundary.errorPath, "errorComponent") : resolveModuleComponent(boundary.errorPath),
|
|
10628
|
+
notFound: boundary.fromRoute ? routeBoundaryComponent(ctx, boundary.notFoundPath, "notFoundComponent") : resolveModuleComponent(boundary.notFoundPath)
|
|
10643
10629
|
}));
|
|
10644
10630
|
routes.push({
|
|
10631
|
+
layouts,
|
|
10645
10632
|
mode,
|
|
10646
10633
|
page,
|
|
10647
10634
|
path,
|
|
@@ -10655,49 +10642,30 @@ function loadProdRoutes(ctx) {
|
|
|
10655
10642
|
}
|
|
10656
10643
|
return { root, routes };
|
|
10657
10644
|
}
|
|
10658
|
-
function
|
|
10645
|
+
function routeBoundaryComponent(ctx, modulePath, field) {
|
|
10646
|
+
const route = modulePath ? ctx.modules[modulePath]?.route : undefined;
|
|
10647
|
+
return isDefinedRouteTerminal(route) ? route[field] : undefined;
|
|
10648
|
+
}
|
|
10649
|
+
function resolveCompiledRuntimePage(module, layouts, root, context) {
|
|
10659
10650
|
if (!isDefinedRouteTerminal(module.route) || typeof module.route.page !== "function") {
|
|
10660
10651
|
return;
|
|
10661
10652
|
}
|
|
10662
|
-
|
|
10663
|
-
const
|
|
10653
|
+
let parent = root.route;
|
|
10654
|
+
for (const { path } of layouts) {
|
|
10655
|
+
const layout = context.modules[path]?.route;
|
|
10656
|
+
if (!isDefinedRouteTerminal(layout) || typeof layout.layout !== "function") {
|
|
10657
|
+
throw invalidNestedLayoutError(path);
|
|
10658
|
+
}
|
|
10659
|
+
parent = adaptDefinedLayout(layout, parent, path);
|
|
10660
|
+
}
|
|
10664
10661
|
return adaptDefinedPage(module.route, parent);
|
|
10665
10662
|
}
|
|
10666
10663
|
function invalidNestedLayoutError(layoutPath) {
|
|
10667
|
-
return new Error(`[furin] ${layoutPath}:
|
|
10668
|
-
export const route = defineRoute("/
|
|
10664
|
+
return new Error(`[furin] ${layoutPath}: a layout file must export \`route = defineRoute(id).config({ mode }).layout(({ children }) => ...)\`, with the file's id. For example, in board/route.tsx:
|
|
10665
|
+
export const route = defineRoute("/board")
|
|
10669
10666
|
.config({ mode: "ssr" })
|
|
10670
10667
|
.layout(({ children }) => <section>{children}</section>);`);
|
|
10671
10668
|
}
|
|
10672
|
-
function resolveCompiledLayoutParent(pagePath, pagesDir, rootRoute, context) {
|
|
10673
|
-
const pageDirectory = pagePath.slice(0, pagePath.lastIndexOf("/"));
|
|
10674
|
-
if (pageDirectory.length <= pagesDir.length) {
|
|
10675
|
-
return rootRoute;
|
|
10676
|
-
}
|
|
10677
|
-
const segments = pageDirectory.slice(pagesDir.length + 1).split("/");
|
|
10678
|
-
let directory = pagesDir;
|
|
10679
|
-
let parent = rootRoute;
|
|
10680
|
-
for (const segment of segments) {
|
|
10681
|
-
directory = `${directory}/${segment}`;
|
|
10682
|
-
for (const candidate of getSourceModuleCandidates(directory, "_route")) {
|
|
10683
|
-
const layoutModule = context.modules[candidate];
|
|
10684
|
-
if (!layoutModule) {
|
|
10685
|
-
continue;
|
|
10686
|
-
}
|
|
10687
|
-
const layout = layoutModule.route;
|
|
10688
|
-
if (!isDefinedRouteTerminal(layout) || typeof layout.layout !== "function") {
|
|
10689
|
-
throw invalidNestedLayoutError(candidate);
|
|
10690
|
-
}
|
|
10691
|
-
parent = adaptDefinedLayout(layout, parent, candidate);
|
|
10692
|
-
break;
|
|
10693
|
-
}
|
|
10694
|
-
}
|
|
10695
|
-
return parent;
|
|
10696
|
-
}
|
|
10697
|
-
var SOURCE_MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
10698
|
-
function getSourceModuleCandidates(dir, name) {
|
|
10699
|
-
return SOURCE_MODULE_EXTENSIONS.map((ext) => `${dir}/${name}${ext}`);
|
|
10700
|
-
}
|
|
10701
10669
|
|
|
10702
10670
|
// src/server/static-export.ts
|
|
10703
10671
|
init_patterns();
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import { type AnyRelations } from "drizzle-orm";
|
|
2
|
+
import type { BunSQLDatabase } from "drizzle-orm/bun-sql/postgres";
|
|
3
|
+
import type { SQLiteBunDatabase } from "drizzle-orm/bun-sqlite";
|
|
3
4
|
import type { AtomicMutationResult, AtomicMutationValue, MutationLease, TransactionalSyncAdapter } from "../adapter.ts";
|
|
4
5
|
import { PostgresSyncAdapter } from "../postgres/index.ts";
|
|
5
6
|
import { SqliteSyncAdapter } from "../sqlite/index.ts";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
type Transaction<Db extends BunSQLiteDatabase<Schema> | BunSQLDatabase<Schema>> = Parameters<Parameters<Db["transaction"]>[0]>[0];
|
|
10
|
-
export declare class DrizzleSqliteSyncAdapter<Db extends BunSQLiteDatabase<Schema>> extends SqliteSyncAdapter implements TransactionalSyncAdapter<Transaction<Db>, "sync"> {
|
|
7
|
+
type Transaction<Db extends SQLiteBunDatabase<AnyRelations> | BunSQLDatabase<AnyRelations>> = Parameters<Parameters<Db["transaction"]>[0]>[0];
|
|
8
|
+
export declare class DrizzleSqliteSyncAdapter<Db extends SQLiteBunDatabase<AnyRelations>> extends SqliteSyncAdapter implements TransactionalSyncAdapter<Transaction<Db>, "sync"> {
|
|
11
9
|
readonly transactionMode: "sync";
|
|
12
10
|
private readonly db;
|
|
13
11
|
constructor(options: {
|
|
@@ -18,7 +16,7 @@ export declare class DrizzleSqliteSyncAdapter<Db extends BunSQLiteDatabase<Schem
|
|
|
18
16
|
});
|
|
19
17
|
executeMutation<T>(lease: MutationLease, callback: (tx: Transaction<Db>) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>): Promise<AtomicMutationResult<T>>;
|
|
20
18
|
}
|
|
21
|
-
export declare class DrizzlePostgresSyncAdapter<Db extends BunSQLDatabase<
|
|
19
|
+
export declare class DrizzlePostgresSyncAdapter<Db extends BunSQLDatabase<AnyRelations>> extends PostgresSyncAdapter implements TransactionalSyncAdapter<Transaction<Db>, "async"> {
|
|
22
20
|
readonly transactionMode: "async";
|
|
23
21
|
private readonly db;
|
|
24
22
|
private readonly syncNamespace;
|
|
@@ -30,13 +28,13 @@ export declare class DrizzlePostgresSyncAdapter<Db extends BunSQLDatabase<Schema
|
|
|
30
28
|
});
|
|
31
29
|
executeMutation<T>(lease: MutationLease, callback: (tx: Transaction<Db>) => AtomicMutationValue<T> | Promise<AtomicMutationValue<T>>): Promise<AtomicMutationResult<T>>;
|
|
32
30
|
}
|
|
33
|
-
export declare function drizzleSyncAdapter<Db extends
|
|
31
|
+
export declare function drizzleSyncAdapter<Db extends SQLiteBunDatabase<AnyRelations>>(options: {
|
|
34
32
|
db: Db & {
|
|
35
33
|
$client: import("bun:sqlite").Database;
|
|
36
34
|
};
|
|
37
35
|
namespace: string;
|
|
38
36
|
}): DrizzleSqliteSyncAdapter<Db>;
|
|
39
|
-
export declare function drizzleSyncAdapter<Db extends BunSQLDatabase<
|
|
37
|
+
export declare function drizzleSyncAdapter<Db extends BunSQLDatabase<AnyRelations>>(options: {
|
|
40
38
|
db: Db & {
|
|
41
39
|
$client: import("bun").SQL;
|
|
42
40
|
};
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The concrete patterns an optional `:x?` segment stands for, as Elysia
|
|
3
|
+
* registers them: `/:lang?/about` → `/about` and `/:lang/about`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function expandOptionalSegments(pattern: string): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Positive when a is more specific: literal > parameter > catch-all. A
|
|
8
|
+
* pattern with optional segments ranks as its most specific variant, so
|
|
9
|
+
* `/:lang?/about` serves `/about` before `/:id` does, as on the server.
|
|
10
|
+
*/
|
|
2
11
|
export declare function compareRouteSpecificity(a: string, b: string): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.2",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -194,14 +194,14 @@
|
|
|
194
194
|
"@prisma/client-runtime-utils": "7.10.1",
|
|
195
195
|
"@types/react": "^19.3.0",
|
|
196
196
|
"@types/react-dom": "^19.3.0",
|
|
197
|
-
"drizzle-orm": "0.
|
|
197
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
198
198
|
"exact-mirror": "1.2.6",
|
|
199
199
|
"expect-type": "^1.4.0",
|
|
200
200
|
"prisma": "7.10.1"
|
|
201
201
|
},
|
|
202
202
|
"peerDependencies": {
|
|
203
203
|
"@types/bun": ">=1.4.0",
|
|
204
|
-
"drizzle-orm": "^0.
|
|
204
|
+
"drizzle-orm": "^1.0.0-rc.4",
|
|
205
205
|
"elysia": "^2.0.0-rc.1",
|
|
206
206
|
"evlog": "^2.33.1",
|
|
207
207
|
"exact-mirror": ">=1.2.6",
|
|
@@ -210,9 +210,6 @@
|
|
|
210
210
|
"typebox": "^1.3.34"
|
|
211
211
|
},
|
|
212
212
|
"peerDependenciesMeta": {
|
|
213
|
-
"@types/bun": {
|
|
214
|
-
"optional": true
|
|
215
|
-
},
|
|
216
213
|
"drizzle-orm": {
|
|
217
214
|
"optional": true
|
|
218
215
|
}
|
package/src/adapter/package.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, relative, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
buildCompileMetadata,
|
|
5
|
+
createBuildFingerprint,
|
|
6
|
+
type RuntimeTargetApp,
|
|
7
|
+
} from "../adapter/runtime-build.ts";
|
|
4
8
|
import { PRODUCTION_DEFINE, runBunBuild } from "../build/bun-build.ts";
|
|
5
9
|
import { buildClient } from "../build/client.ts";
|
|
6
10
|
import { buildEntrySource, PRERENDER_SNAPSHOT_FILE } from "../build/entry-template.ts";
|
|
@@ -56,7 +60,7 @@ export async function buildPackageTarget(
|
|
|
56
60
|
metafilePath: options.analyze ? join(buildRoot, "analysis", "package-client.json") : undefined,
|
|
57
61
|
optimizeImports: options.optimizeImports,
|
|
58
62
|
outDir: targetDir,
|
|
59
|
-
pagesDir,
|
|
63
|
+
pages: { pagesDir, style: app.style },
|
|
60
64
|
routeRegistry: app.routeRegistry,
|
|
61
65
|
plugins: options.plugins,
|
|
62
66
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -93,38 +97,7 @@ export async function buildPackageTarget(
|
|
|
93
97
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
94
98
|
writeFileSync(join(clientDir, "index.html"), indexHtml);
|
|
95
99
|
|
|
96
|
-
const rootConventions =
|
|
97
|
-
root.errorPath || root.notFoundPath
|
|
98
|
-
? {
|
|
99
|
-
errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
|
|
100
|
-
notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined,
|
|
101
|
-
}
|
|
102
|
-
: undefined;
|
|
103
|
-
const routeMetadata: Record<
|
|
104
|
-
string,
|
|
105
|
-
{
|
|
106
|
-
requestKeys?: string[];
|
|
107
|
-
requestKeysByLoader?: string[][];
|
|
108
|
-
segmentBoundaries: Array<{
|
|
109
|
-
depth: number;
|
|
110
|
-
path: string;
|
|
111
|
-
errorPath?: string;
|
|
112
|
-
notFoundPath?: string;
|
|
113
|
-
}>;
|
|
114
|
-
}
|
|
115
|
-
> = {};
|
|
116
|
-
for (const route of routes) {
|
|
117
|
-
routeMetadata[toPosixPath(route.path)] = {
|
|
118
|
-
requestKeys: route.requestKeys,
|
|
119
|
-
requestKeysByLoader: route.requestKeysByLoader,
|
|
120
|
-
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
121
|
-
depth: b.depth,
|
|
122
|
-
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
123
|
-
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
124
|
-
path: toPosixPath(b.path),
|
|
125
|
-
})),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
100
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
128
101
|
|
|
129
102
|
// 1. register.ts — context registration side-effect module.
|
|
130
103
|
const registerSource = buildEntrySource({
|
|
@@ -194,7 +167,7 @@ const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
|
194
167
|
* Mounts this packaged furin app as an Elysia plugin.
|
|
195
168
|
*
|
|
196
169
|
* @param {object} [options] Extra furin() options (logger, sync, ...) —
|
|
197
|
-
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
170
|
+
* pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden.
|
|
198
171
|
* @returns {ReturnType<typeof import("@teyik0/furin").furin>}
|
|
199
172
|
*/
|
|
200
173
|
export function createFurinApp(options = {}) {
|
|
@@ -202,6 +175,7 @@ export function createFurinApp(options = {}) {
|
|
|
202
175
|
...options,
|
|
203
176
|
pagesDir: PAGES_DIR,
|
|
204
177
|
prefix: ${JSON.stringify(prefix)},
|
|
178
|
+
style: ${JSON.stringify(app.style)},
|
|
205
179
|
clientDir: CLIENT_DIR,
|
|
206
180
|
});
|
|
207
181
|
}
|
|
@@ -212,8 +186,8 @@ export const prefix = ${JSON.stringify(prefix)};
|
|
|
212
186
|
|
|
213
187
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
214
188
|
|
|
215
|
-
/** Extra furin() options — pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
216
|
-
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
189
|
+
/** Extra furin() options — pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden. */
|
|
190
|
+
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "style" | "clientDir">;
|
|
217
191
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
218
192
|
export declare const prefix: string;
|
|
219
193
|
`;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "../build/route-metadata.ts";
|
|
13
13
|
import { toPosixPath } from "../build/shared.ts";
|
|
14
14
|
import type { BuildAppOptions } from "../build/types.ts";
|
|
15
|
+
import type { RouteInstanceSpec } from "../plugin/route-manifest.ts";
|
|
15
16
|
import type { RouteRegistrySnapshot } from "../plugin/route-registry.ts";
|
|
16
17
|
import { composableRouteModuleSpecifier } from "../plugin/route-registry.ts";
|
|
17
18
|
import { routeSourcePaths } from "../plugin/route-tree.ts";
|
|
@@ -275,11 +276,13 @@ export function buildCompileMetadata(root: BuildRoot | RootLayout, routes: Build
|
|
|
275
276
|
const routeMetadata: NonNullable<EntryAppContext["routeMetadata"]> = {};
|
|
276
277
|
for (const route of routes) {
|
|
277
278
|
routeMetadata[toPosixPath(route.path)] = {
|
|
279
|
+
layouts: route.layouts.map((layout) => ({ ...layout, path: toPosixPath(layout.path) })),
|
|
278
280
|
requestKeys: route.requestKeys,
|
|
279
281
|
requestKeysByLoader: route.requestKeysByLoader,
|
|
280
282
|
segmentBoundaries: route.segmentBoundaries.map((boundary) => ({
|
|
281
283
|
depth: boundary.depth,
|
|
282
284
|
errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
|
|
285
|
+
...(boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {}),
|
|
283
286
|
notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
|
|
284
287
|
path: toPosixPath(boundary.path),
|
|
285
288
|
})),
|
|
@@ -290,9 +293,7 @@ export function buildCompileMetadata(root: BuildRoot | RootLayout, routes: Build
|
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
/** One mounted app's build input (root + routes scanned from its pagesDir). */
|
|
293
|
-
export interface RuntimeTargetApp {
|
|
294
|
-
pagesDir: string;
|
|
295
|
-
prefix: string;
|
|
296
|
+
export interface RuntimeTargetApp extends RouteInstanceSpec {
|
|
296
297
|
root: BuildRoot | RootLayout;
|
|
297
298
|
routeRegistry?: RouteRegistrySnapshot;
|
|
298
299
|
routes: BuildRouteInput[];
|
|
@@ -412,7 +413,7 @@ export async function buildRuntimeApp(
|
|
|
412
413
|
: undefined,
|
|
413
414
|
optimizeImports: options.optimizeImports,
|
|
414
415
|
outDir: targetDir,
|
|
415
|
-
pagesDir: app.pagesDir,
|
|
416
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
416
417
|
routeRegistry: app.routeRegistry,
|
|
417
418
|
plugins: options.plugins,
|
|
418
419
|
preloadRouteChunks: options.preload?.routeChunks,
|
package/src/adapter/static.ts
CHANGED
|
@@ -498,7 +498,7 @@ export async function buildStaticTarget(
|
|
|
498
498
|
metafilePath: options.analyze ? join(buildRoot, "analysis", "static-client.json") : undefined,
|
|
499
499
|
optimizeImports: options.optimizeImports,
|
|
500
500
|
outDir: targetDir,
|
|
501
|
-
pagesDir:
|
|
501
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
502
502
|
routeRegistry: app.routeRegistry,
|
|
503
503
|
plugins: options.plugins,
|
|
504
504
|
preloadRouteChunks: options.preload?.routeChunks,
|
package/src/adapter/vercel.ts
CHANGED
|
@@ -158,7 +158,8 @@ function functionNameForPath(
|
|
|
158
158
|
return "[...splat]";
|
|
159
159
|
}
|
|
160
160
|
if (segment.startsWith(":")) {
|
|
161
|
-
|
|
161
|
+
// `:lang?` → `[[lang]]`: `?` is not portable in function directory names.
|
|
162
|
+
return segment.endsWith("?") ? `[[${segment.slice(1, -1)}]]` : `[${segment.slice(1)}]`;
|
|
162
163
|
}
|
|
163
164
|
const sanitized = segment.replace(UNSAFE_FUNCTION_PATH_RE, "-");
|
|
164
165
|
if (sanitized === segment && segment !== "." && segment !== "..") {
|
package/src/build/client.ts
CHANGED
|
@@ -54,7 +54,7 @@ export async function buildClient(
|
|
|
54
54
|
metafilePath,
|
|
55
55
|
optimizeImports,
|
|
56
56
|
reactCompiler,
|
|
57
|
-
|
|
57
|
+
pages,
|
|
58
58
|
routeRegistry,
|
|
59
59
|
}: BuildClientOptions
|
|
60
60
|
): Promise<BuildClientResult> {
|
|
@@ -136,8 +136,8 @@ export async function buildClient(
|
|
|
136
136
|
hydrateEntry.plugin,
|
|
137
137
|
...(plugins ?? []),
|
|
138
138
|
...(!clientLogging ? [routerLoggerPlugin] : []),
|
|
139
|
-
...(
|
|
140
|
-
? [createRoutesPlugin({ instances: [{
|
|
139
|
+
...(pages
|
|
140
|
+
? [createRoutesPlugin({ instances: [{ ...pages, prefix: basePath, routeRegistry }], target: "client" })]
|
|
141
141
|
: []),
|
|
142
142
|
createClientStripPlugin({ mode: "build" }),
|
|
143
143
|
],
|
|
@@ -134,7 +134,7 @@ Bun.plugin(isomorphicTransformPlugin("server"));
|
|
|
134
134
|
const discovered: DiscoveredApp[] = [];
|
|
135
135
|
process.env.ELYSIA_AOT_BUILD = "1";
|
|
136
136
|
for (const spec of apps) {
|
|
137
|
-
const { root, routes } = await scanPages(spec
|
|
137
|
+
const { root, routes } = await scanPages(spec);
|
|
138
138
|
discovered.push({
|
|
139
139
|
...spec,
|
|
140
140
|
routeRegistry: await snapshotRouteRegistry(spec),
|
package/src/build/elysia-aot.ts
CHANGED
|
@@ -58,10 +58,10 @@ export function handleWSResponse(){return e()}
|
|
|
58
58
|
`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function mountLabel(rootDir: string, { pagesDir, prefix }: RouteInstanceSpec): string {
|
|
61
|
+
function mountLabel(rootDir: string, { pagesDir, prefix, style }: RouteInstanceSpec): string {
|
|
62
62
|
const absolute = resolve(rootDir, pagesDir);
|
|
63
63
|
const path = existsSync(absolute) ? realpathSync(absolute) : absolute;
|
|
64
|
-
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative(rootDir, path) || "."})`;
|
|
64
|
+
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative(rootDir, path) || "."}, style ${style})`;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|