@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.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/dist/adapter/runtime-build.d.ts +7 -3
  3. package/dist/adapter/vercel.js +31 -6
  4. package/dist/build/client.d.ts +1 -1
  5. package/dist/build/entry-template.d.ts +3 -12
  6. package/dist/build/entry-template.ts +3 -15
  7. package/dist/build/hydrate.d.ts +6 -1
  8. package/dist/build/index.d.ts +1 -1
  9. package/dist/build/index.js +565 -401
  10. package/dist/build/route-metadata.d.ts +2 -2
  11. package/dist/build/route-types.d.ts +1 -1
  12. package/dist/build/types.d.ts +10 -4
  13. package/dist/cli/dev-worker.ts +10 -4
  14. package/dist/cli/index.js +624 -445
  15. package/dist/client/chunks/{client-xy6g38kx.js → client-a7spxfnn.js} +24 -5
  16. package/dist/client/chunks/{client-rjhxgt64.js → client-d9v49jwz.js} +1 -1
  17. package/dist/client/chunks/{client-k29262a4.js → client-rdxyrw11.js} +1 -1
  18. package/dist/client/define-route.d.ts +14 -0
  19. package/dist/client/internal/runtime-types.d.ts +8 -0
  20. package/dist/client/link.js +20 -17
  21. package/dist/client/router/link-utils.d.ts +3 -2
  22. package/dist/client/router/search/index.js +2 -2
  23. package/dist/client/router/types.d.ts +9 -3
  24. package/dist/client.js +22 -6
  25. package/dist/config.d.ts +4 -0
  26. package/dist/config.js +4 -1
  27. package/dist/define-route.d.ts +53 -12
  28. package/dist/furin.d.ts +13 -3
  29. package/dist/furin.js +815 -661
  30. package/dist/plugin/route-config.d.ts +3 -3
  31. package/dist/plugin/route-manifest.d.ts +46 -0
  32. package/dist/plugin/route-tree.d.ts +13 -29
  33. package/dist/routes.d.ts +2 -2
  34. package/dist/server/dev/runtime.d.ts +2 -1
  35. package/dist/server/internal.d.ts +6 -0
  36. package/dist/server/internal.js +97 -114
  37. package/dist/server/registrations.d.ts +4 -2
  38. package/dist/server/render/index.d.ts +0 -1
  39. package/dist/server/render/index.ts +0 -1
  40. package/dist/server/render/shell.d.ts +1 -13
  41. package/dist/server/render/shell.ts +1 -90
  42. package/dist/server/router/defined-route.d.ts +4 -0
  43. package/dist/server/router/discovery.d.ts +14 -4
  44. package/dist/server/router/hmr.d.ts +12 -12
  45. package/dist/server/router/patterns.d.ts +4 -12
  46. package/dist/server/router/types.d.ts +16 -1
  47. package/dist/server/static-export.js +128 -158
  48. package/dist/server/sync/drizzle/index.d.ts +8 -10
  49. package/dist/shared/not-found.d.ts +1 -1
  50. package/dist/shared/route-specificity.d.ts +10 -1
  51. package/package.json +8 -11
  52. package/src/adapter/package.ts +11 -37
  53. package/src/adapter/runtime-build.ts +5 -4
  54. package/src/adapter/static.ts +1 -1
  55. package/src/adapter/vercel.ts +2 -1
  56. package/src/build/client.ts +3 -3
  57. package/src/build/discover-pages-process.ts +1 -1
  58. package/src/build/elysia-aot.ts +2 -2
  59. package/src/build/entry-template.ts +3 -15
  60. package/src/build/hydrate.ts +12 -6
  61. package/src/build/index.ts +19 -9
  62. package/src/build/route-metadata.ts +15 -8
  63. package/src/build/route-types.ts +18 -43
  64. package/src/build/types.ts +12 -5
  65. package/src/cli/config.ts +6 -0
  66. package/src/cli/dev-worker.ts +10 -4
  67. package/src/cli/dev.ts +41 -26
  68. package/src/cli/index.ts +30 -14
  69. package/src/client/define-route.ts +29 -4
  70. package/src/client/internal/runtime-types.ts +8 -0
  71. package/src/client/link.tsx +21 -22
  72. package/src/client/router/context.ts +8 -7
  73. package/src/client/router/link-utils.ts +16 -8
  74. package/src/client/router/provider.tsx +5 -0
  75. package/src/client/router/types.ts +40 -14
  76. package/src/config.ts +5 -0
  77. package/src/define-route.ts +85 -16
  78. package/src/furin.ts +31 -7
  79. package/src/plugin/dev-routes.ts +8 -17
  80. package/src/plugin/route-config.ts +77 -62
  81. package/src/plugin/route-manifest.ts +437 -0
  82. package/src/plugin/route-modules.ts +6 -1
  83. package/src/plugin/route-registry.ts +7 -21
  84. package/src/plugin/route-tree.ts +71 -181
  85. package/src/routes.ts +2 -2
  86. package/src/server/dev/runtime.ts +16 -22
  87. package/src/server/internal.ts +4 -1
  88. package/src/server/registrations.ts +5 -2
  89. package/src/server/render/index.ts +0 -1
  90. package/src/server/render/shell.ts +1 -90
  91. package/src/server/render/static-params.ts +2 -10
  92. package/src/server/router/defined-route.ts +8 -0
  93. package/src/server/router/discovery.ts +237 -196
  94. package/src/server/router/hmr.ts +45 -63
  95. package/src/server/router/patterns.ts +41 -117
  96. package/src/server/router/types.ts +17 -1
  97. package/src/server/sync/drizzle/index.ts +18 -19
  98. package/src/shared/not-found.ts +1 -1
  99. package/src/shared/route-specificity.ts +34 -2
  100. 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 compareRouteSpecificity(a, b) {
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
- if (!params) {
3174
- return to;
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
- let url = to.replaceAll(/:([a-zA-Z0-9_]+)/g, (match, name) => (name in params) ? encodeURIComponent(String(params[name])) : match);
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
- paramNames.push(pattern.slice(start, i));
3717
- source += sources.param;
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 += sources.catchAll;
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
- const params = {};
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 DYNAMIC_PARAMETER_NAME_RE, ROUTE_GROUP_RE, REGEX_META_CHARS_RE;
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.tsx layout.");
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)) {
@@ -8718,6 +8707,7 @@ var FALLBACK_SEARCH_STORE = createSearchStore({
8718
8707
  });
8719
8708
  var SearchStoreContext = createContext5(null);
8720
8709
  // src/client/link.tsx
8710
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
8721
8711
  "use client";
8722
8712
  function resolveLinkHref({ to, params, search, hash }, router2) {
8723
8713
  const resolvedTo = applyLinkParams(to, params);
@@ -8786,12 +8776,12 @@ function LinkInteractive({
8786
8776
  if (target !== null) {
8787
8777
  prefetch(target, { staleTime: effectiveStaleTime });
8788
8778
  }
8789
- }, [prefetch, logicalHref, effectiveStaleTime, router2.basePath]);
8779
+ }, [prefetch, effectiveStaleTime, router2.basePath]);
8790
8780
  useEffect2(() => {
8791
8781
  if (effectivePreload === "render") {
8792
8782
  triggerPrefetch();
8793
8783
  }
8794
- }, [effectivePreload, triggerPrefetch]);
8784
+ }, [effectivePreload, triggerPrefetch, logicalHref]);
8795
8785
  useEffect2(() => {
8796
8786
  if (effectivePreload !== "viewport" || !anchorRef.current) {
8797
8787
  return;
@@ -8804,7 +8794,7 @@ function LinkInteractive({
8804
8794
  }, { rootMargin: "200px" });
8805
8795
  observer.observe(anchorRef.current);
8806
8796
  return () => observer.disconnect();
8807
- }, [effectivePreload, triggerPrefetch]);
8797
+ }, [effectivePreload, triggerPrefetch, logicalHref]);
8808
8798
  useEffect2(() => () => {
8809
8799
  if (intentTimerRef.current !== null) {
8810
8800
  clearTimeout(intentTimerRef.current);
@@ -8833,7 +8823,7 @@ function LinkInteractive({
8833
8823
  }
8834
8824
  e.preventDefault();
8835
8825
  if (typeof window !== "undefined" && router2.navigate === CLIENT_FALLBACK_ROUTER.navigate) {
8836
- window.location.href = href;
8826
+ window.location.assign(href);
8837
8827
  return;
8838
8828
  }
8839
8829
  router2.navigate(target, { replace, resetScroll: resetScroll ?? true });
@@ -8857,7 +8847,7 @@ function LinkInteractive({
8857
8847
  triggerPrefetch();
8858
8848
  }
8859
8849
  };
8860
- return createElement6("a", {
8850
+ return /* @__PURE__ */ jsxDEV3("a", {
8861
8851
  "data-furin-link": true,
8862
8852
  href,
8863
8853
  onClick: handleClick,
@@ -8868,8 +8858,9 @@ function LinkInteractive({
8868
8858
  ...isActive ? { "data-status": "active" } : {},
8869
8859
  ...anchorProps,
8870
8860
  ...extraProps,
8871
- ...disabled ? { "aria-disabled": true } : {}
8872
- }, resolvedChildren);
8861
+ ...disabled ? { "aria-disabled": true } : {},
8862
+ children: resolvedChildren
8863
+ }, undefined, false, undefined, this);
8873
8864
  }
8874
8865
  var SSR_FALLBACK_ROUTER = {
8875
8866
  basePath: "",
@@ -8929,7 +8920,7 @@ function Link(props) {
8929
8920
  }
8930
8921
 
8931
8922
  // src/client/default-screens.tsx
8932
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
8923
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
8933
8924
  var FONT_SANS = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
8934
8925
  var FONT_MONO = 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace';
8935
8926
  var COLOR_BG = "#000000";
@@ -8980,7 +8971,7 @@ function CornerBracket({ corner }) {
8980
8971
  [`border${top ? "Top" : "Bottom"}`]: `2px solid ${COLOR_BRACKET}`,
8981
8972
  [`border${left ? "Left" : "Right"}`]: `2px solid ${COLOR_BRACKET}`
8982
8973
  };
8983
- return /* @__PURE__ */ jsxDEV3("span", {
8974
+ return /* @__PURE__ */ jsxDEV4("span", {
8984
8975
  "aria-hidden": "true",
8985
8976
  style
8986
8977
  }, undefined, false, undefined, this);
@@ -9086,32 +9077,32 @@ html, body {
9086
9077
  }
9087
9078
  `;
9088
9079
  function ScreenFrame({ badge, children }) {
9089
- return /* @__PURE__ */ jsxDEV3("div", {
9080
+ return /* @__PURE__ */ jsxDEV4("div", {
9090
9081
  style: PAGE_STYLE,
9091
9082
  children: [
9092
- /* @__PURE__ */ jsxDEV3("style", {
9083
+ /* @__PURE__ */ jsxDEV4("style", {
9093
9084
  children: RESET_CSS
9094
9085
  }, undefined, false, undefined, this),
9095
- /* @__PURE__ */ jsxDEV3("div", {
9086
+ /* @__PURE__ */ jsxDEV4("div", {
9096
9087
  style: FRAME_STYLE,
9097
9088
  children: [
9098
- /* @__PURE__ */ jsxDEV3(CornerBracket, {
9089
+ /* @__PURE__ */ jsxDEV4(CornerBracket, {
9099
9090
  corner: "tl"
9100
9091
  }, undefined, false, undefined, this),
9101
- /* @__PURE__ */ jsxDEV3(CornerBracket, {
9092
+ /* @__PURE__ */ jsxDEV4(CornerBracket, {
9102
9093
  corner: "tr"
9103
9094
  }, undefined, false, undefined, this),
9104
- /* @__PURE__ */ jsxDEV3(CornerBracket, {
9095
+ /* @__PURE__ */ jsxDEV4(CornerBracket, {
9105
9096
  corner: "bl"
9106
9097
  }, undefined, false, undefined, this),
9107
- /* @__PURE__ */ jsxDEV3(CornerBracket, {
9098
+ /* @__PURE__ */ jsxDEV4(CornerBracket, {
9108
9099
  corner: "br"
9109
9100
  }, undefined, false, undefined, this),
9110
- /* @__PURE__ */ jsxDEV3("div", {
9101
+ /* @__PURE__ */ jsxDEV4("div", {
9111
9102
  style: CARD_STYLE,
9112
9103
  children: [
9113
9104
  badge,
9114
- /* @__PURE__ */ jsxDEV3("hr", {
9105
+ /* @__PURE__ */ jsxDEV4("hr", {
9115
9106
  style: DIVIDER_STYLE
9116
9107
  }, undefined, false, undefined, this),
9117
9108
  children
@@ -9123,41 +9114,41 @@ function ScreenFrame({ badge, children }) {
9123
9114
  }, undefined, true, undefined, this);
9124
9115
  }
9125
9116
  function DefaultErrorScreen({ message, digest, reset }) {
9126
- return /* @__PURE__ */ jsxDEV3(ScreenFrame, {
9127
- badge: /* @__PURE__ */ jsxDEV3("div", {
9117
+ return /* @__PURE__ */ jsxDEV4(ScreenFrame, {
9118
+ badge: /* @__PURE__ */ jsxDEV4("div", {
9128
9119
  style: BADGE_STYLE,
9129
9120
  children: "500 \u2014 ERROR"
9130
9121
  }, undefined, false, undefined, this),
9131
9122
  children: [
9132
- /* @__PURE__ */ jsxDEV3("h1", {
9123
+ /* @__PURE__ */ jsxDEV4("h1", {
9133
9124
  style: HEADING_STYLE,
9134
9125
  children: "Something went wrong"
9135
9126
  }, undefined, false, undefined, this),
9136
- /* @__PURE__ */ jsxDEV3("div", {
9127
+ /* @__PURE__ */ jsxDEV4("div", {
9137
9128
  style: CODE_BOX_STYLE,
9138
9129
  children: [
9139
- /* @__PURE__ */ jsxDEV3("span", {
9130
+ /* @__PURE__ */ jsxDEV4("span", {
9140
9131
  style: CODE_LABEL_STYLE,
9141
9132
  children: "CODE:"
9142
9133
  }, undefined, false, undefined, this),
9143
- /* @__PURE__ */ jsxDEV3("span", {
9134
+ /* @__PURE__ */ jsxDEV4("span", {
9144
9135
  children: digest
9145
9136
  }, undefined, false, undefined, this)
9146
9137
  ]
9147
9138
  }, undefined, true, undefined, this),
9148
- /* @__PURE__ */ jsxDEV3("p", {
9139
+ /* @__PURE__ */ jsxDEV4("p", {
9149
9140
  style: DESCRIPTION_WRAPPER_STYLE,
9150
9141
  children: message ? message : "We encountered an unexpected error. Please try again or return to the home page."
9151
9142
  }, undefined, false, undefined, this),
9152
- /* @__PURE__ */ jsxDEV3("div", {
9143
+ /* @__PURE__ */ jsxDEV4("div", {
9153
9144
  style: ACTIONS_STYLE,
9154
9145
  children: [
9155
- /* @__PURE__ */ jsxDEV3(Link, {
9146
+ /* @__PURE__ */ jsxDEV4(Link, {
9156
9147
  style: BUTTON_PRIMARY,
9157
9148
  to: "/",
9158
9149
  children: "Go Home"
9159
9150
  }, undefined, false, undefined, this),
9160
- /* @__PURE__ */ jsxDEV3("button", {
9151
+ /* @__PURE__ */ jsxDEV4("button", {
9161
9152
  onClick: reset,
9162
9153
  style: BUTTON_SECONDARY,
9163
9154
  type: "button",
@@ -9169,23 +9160,23 @@ function DefaultErrorScreen({ message, digest, reset }) {
9169
9160
  }, undefined, true, undefined, this);
9170
9161
  }
9171
9162
  function DefaultNotFoundScreen({ message }) {
9172
- return /* @__PURE__ */ jsxDEV3(ScreenFrame, {
9173
- badge: /* @__PURE__ */ jsxDEV3("div", {
9163
+ return /* @__PURE__ */ jsxDEV4(ScreenFrame, {
9164
+ badge: /* @__PURE__ */ jsxDEV4("div", {
9174
9165
  style: BADGE_STYLE,
9175
9166
  children: "404 \u2014 NOT FOUND"
9176
9167
  }, undefined, false, undefined, this),
9177
9168
  children: [
9178
- /* @__PURE__ */ jsxDEV3("h1", {
9169
+ /* @__PURE__ */ jsxDEV4("h1", {
9179
9170
  style: HEADING_STYLE,
9180
9171
  children: "This page does not exist"
9181
9172
  }, undefined, false, undefined, this),
9182
- /* @__PURE__ */ jsxDEV3("p", {
9173
+ /* @__PURE__ */ jsxDEV4("p", {
9183
9174
  style: DESCRIPTION_WRAPPER_STYLE,
9184
9175
  children: message ? message : "The page you are looking for could not be found. It may have been moved or removed."
9185
9176
  }, undefined, false, undefined, this),
9186
- /* @__PURE__ */ jsxDEV3("div", {
9177
+ /* @__PURE__ */ jsxDEV4("div", {
9187
9178
  style: ACTIONS_STYLE,
9188
- children: /* @__PURE__ */ jsxDEV3(Link, {
9179
+ children: /* @__PURE__ */ jsxDEV4(Link, {
9189
9180
  style: BUTTON_PRIMARY,
9190
9181
  to: "/",
9191
9182
  children: "Go Home"
@@ -9194,18 +9185,18 @@ function DefaultNotFoundScreen({ message }) {
9194
9185
  ]
9195
9186
  }, undefined, true, undefined, this);
9196
9187
  }
9197
- var DefaultErrorFallback = ({ error, reset }) => /* @__PURE__ */ jsxDEV3(DefaultErrorScreen, {
9188
+ var DefaultErrorFallback = ({ error, reset }) => /* @__PURE__ */ jsxDEV4(DefaultErrorScreen, {
9198
9189
  digest: error.digest,
9199
9190
  message: error.message,
9200
9191
  reset
9201
9192
  }, undefined, false, undefined, this);
9202
- var DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV3(DefaultNotFoundScreen, {
9193
+ var DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV4(DefaultNotFoundScreen, {
9203
9194
  message: error.message
9204
9195
  }, undefined, false, undefined, this);
9205
9196
 
9206
9197
  // src/server/render/element.tsx
9207
9198
  init_instance();
9208
- import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
9199
+ import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
9209
9200
  function errorMessageOf(err) {
9210
9201
  if (err instanceof Error) {
9211
9202
  return err.message;
@@ -9233,7 +9224,7 @@ function errorMessageForRender(component, error, messageOverride) {
9233
9224
  function buildErrorElement(component, error, digest, messageOverride, status) {
9234
9225
  const ErrorView = component ?? DefaultErrorFallback;
9235
9226
  const message = errorMessageForRender(component, error, messageOverride);
9236
- return /* @__PURE__ */ jsxDEV4(ErrorView, {
9227
+ return /* @__PURE__ */ jsxDEV5(ErrorView, {
9237
9228
  error: { digest, message, status },
9238
9229
  reset: SERVER_RESET_NOOP2
9239
9230
  }, undefined, false, undefined, this);
@@ -10345,8 +10336,6 @@ function renderForPath(route, params, root, origin, mode, basePath, searchRoutes
10345
10336
  }
10346
10337
 
10347
10338
  // src/server/render/static-params.ts
10348
- import { dirname as dirname2, relative } from "path";
10349
- init_patterns();
10350
10339
  var STATIC_PARAMS_CONCURRENCY = 4;
10351
10340
  var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
10352
10341
  function collectStaticParamsStages(route) {
@@ -10362,17 +10351,11 @@ function collectStaticParamsStages(route) {
10362
10351
  return stages;
10363
10352
  }
10364
10353
  function ancestorPattern(route, ancestors) {
10365
- const rootSourcePath = route.routeChain[0]?.sourcePath;
10366
10354
  const ancestorSourcePath = ancestors.at(-1)?.sourcePath;
10367
- if (rootSourcePath === undefined || ancestorSourcePath === undefined) {
10368
- return route.pattern;
10369
- }
10370
- const pagesDir = dirname2(rootSourcePath);
10371
- const ancestorDir = dirname2(ancestorSourcePath);
10372
- if (ancestorDir === pagesDir) {
10355
+ if (ancestors.length <= 1) {
10373
10356
  return "/";
10374
10357
  }
10375
- return filePathToPattern(`${relative(pagesDir, ancestorDir)}/index.tsx`);
10358
+ return route.layouts.find(({ path }) => path === ancestorSourcePath)?.pattern ?? route.pattern;
10376
10359
  }
10377
10360
  function createBuildContext(pattern, params, origin) {
10378
10361
  const path = resolvePath(pattern, params);
@@ -10558,9 +10541,11 @@ function adaptDefinedLayout(route, parent, sourcePath) {
10558
10541
  const component = route.component;
10559
10542
  return {
10560
10543
  __type: "FURIN_ROUTE",
10544
+ errorComponent: route.errorComponent,
10561
10545
  layout: component,
10562
10546
  loader: route.loader,
10563
10547
  mode: route.mode,
10548
+ notFoundComponent: route.notFoundComponent,
10564
10549
  params: route.schemas?.params,
10565
10550
  ...parent ? { parent } : {},
10566
10551
  query: route.schemas?.query,
@@ -10585,9 +10570,11 @@ function adaptDefinedPage(route, parent) {
10585
10570
  requestLoader: route.requestLoader
10586
10571
  },
10587
10572
  component,
10573
+ errorComponent: route.errorComponent,
10588
10574
  head,
10589
10575
  loader: route.loader,
10590
10576
  mode: route.mode,
10577
+ notFoundComponent: route.notFoundComponent,
10591
10578
  revalidate: route.revalidate,
10592
10579
  staticParams: route.staticParams,
10593
10580
  tags: copyTags(route.tags)
@@ -10610,7 +10597,7 @@ function collectRouteTags(routeChain, page) {
10610
10597
  function loadProdRoutes(ctx) {
10611
10598
  const rootExport = ctx.modules[ctx.rootPath]?.route;
10612
10599
  if (!isDefinedRouteTerminal(rootExport) || typeof rootExport.layout !== "function") {
10613
- throw new Error("[furin] root.tsx: defineRootRoute().layout() not found in CompileContext.");
10600
+ throw new Error(`[furin] ${ctx.rootPath}: defineRootRoute().layout() not found in CompileContext.`);
10614
10601
  }
10615
10602
  const rootRoute = adaptDefinedLayout(rootExport, undefined, ctx.rootPath);
10616
10603
  function resolveModuleComponent(modPath) {
@@ -10620,26 +10607,28 @@ function loadProdRoutes(ctx) {
10620
10607
  return ctx.modules[modPath]?.default;
10621
10608
  }
10622
10609
  const root = {
10623
- error: resolveModuleComponent(ctx.rootConventions?.errorPath),
10624
- notFound: resolveModuleComponent(ctx.rootConventions?.notFoundPath),
10610
+ error: rootRoute.errorComponent ?? resolveModuleComponent(ctx.rootConventions?.errorPath),
10611
+ notFound: rootRoute.notFoundComponent ?? resolveModuleComponent(ctx.rootConventions?.notFoundPath),
10625
10612
  path: ctx.rootPath,
10626
10613
  route: rootRoute
10627
10614
  };
10628
10615
  const routes = [];
10629
10616
  for (const { pattern, path, mode } of ctx.routes) {
10630
- const page = resolveCompiledRuntimePage(ctx.modules[path] ?? {}, path, root, ctx);
10617
+ const meta = ctx.routeMetadata?.[path];
10618
+ const layouts = meta?.layouts ?? [];
10619
+ const page = resolveCompiledRuntimePage(ctx.modules[path] ?? {}, layouts, root, ctx);
10631
10620
  if (!page) {
10632
10621
  throw new Error(`[furin] ${path}: invalid page module in CompileContext.`);
10633
10622
  }
10634
10623
  const routeChain = collectRouteChainFromRoute(page._route);
10635
10624
  validateRouteChain(routeChain, root.route, path);
10636
- const meta = ctx.routeMetadata?.[path];
10637
- const boundaries = (meta?.segmentBoundaries ?? []).map((b) => ({
10638
- ...b,
10639
- error: resolveModuleComponent(b.errorPath),
10640
- 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)
10641
10629
  }));
10642
10630
  routes.push({
10631
+ layouts,
10643
10632
  mode,
10644
10633
  page,
10645
10634
  path,
@@ -10653,49 +10642,30 @@ function loadProdRoutes(ctx) {
10653
10642
  }
10654
10643
  return { root, routes };
10655
10644
  }
10656
- function resolveCompiledRuntimePage(module, path, root, context) {
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) {
10657
10650
  if (!isDefinedRouteTerminal(module.route) || typeof module.route.page !== "function") {
10658
10651
  return;
10659
10652
  }
10660
- const pagesDir = root.path.slice(0, root.path.lastIndexOf("/"));
10661
- const parent = resolveCompiledLayoutParent(path, pagesDir, root.route, context);
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
+ }
10662
10661
  return adaptDefinedPage(module.route, parent);
10663
10662
  }
10664
10663
  function invalidNestedLayoutError(layoutPath) {
10665
- return new Error(`[furin] ${layoutPath}: _route.tsx must export \`route = defineRoute(id).config({ mode }).layout(({ children }) => ...)\`, with the file's id. For example, in blog/_route.tsx:
10666
- export const route = defineRoute("/blog/_route")
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")
10667
10666
  .config({ mode: "ssr" })
10668
10667
  .layout(({ children }) => <section>{children}</section>);`);
10669
10668
  }
10670
- function resolveCompiledLayoutParent(pagePath, pagesDir, rootRoute, context) {
10671
- const pageDirectory = pagePath.slice(0, pagePath.lastIndexOf("/"));
10672
- if (pageDirectory.length <= pagesDir.length) {
10673
- return rootRoute;
10674
- }
10675
- const segments = pageDirectory.slice(pagesDir.length + 1).split("/");
10676
- let directory = pagesDir;
10677
- let parent = rootRoute;
10678
- for (const segment of segments) {
10679
- directory = `${directory}/${segment}`;
10680
- for (const candidate of getSourceModuleCandidates(directory, "_route")) {
10681
- const layoutModule = context.modules[candidate];
10682
- if (!layoutModule) {
10683
- continue;
10684
- }
10685
- const layout = layoutModule.route;
10686
- if (!isDefinedRouteTerminal(layout) || typeof layout.layout !== "function") {
10687
- throw invalidNestedLayoutError(candidate);
10688
- }
10689
- parent = adaptDefinedLayout(layout, parent, candidate);
10690
- break;
10691
- }
10692
- }
10693
- return parent;
10694
- }
10695
- var SOURCE_MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
10696
- function getSourceModuleCandidates(dir, name) {
10697
- return SOURCE_MODULE_EXTENSIONS.map((ext) => `${dir}/${name}${ext}`);
10698
- }
10699
10669
 
10700
10670
  // src/server/static-export.ts
10701
10671
  init_patterns();
@@ -1,13 +1,11 @@
1
- import type { BunSQLDatabase } from "drizzle-orm/bun-sql";
2
- import type { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite";
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
- interface Schema {
7
- [table: string]: unknown;
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<Schema>> extends PostgresSyncAdapter implements TransactionalSyncAdapter<Transaction<Db>, "async"> {
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 BunSQLiteDatabase<Schema>>(options: {
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<Schema>>(options: {
37
+ export declare function drizzleSyncAdapter<Db extends BunSQLDatabase<AnyRelations>>(options: {
40
38
  db: Db & {
41
39
  $client: import("bun").SQL;
42
40
  };
@@ -15,5 +15,5 @@ export declare class FurinNotFoundError extends Error {
15
15
  readonly data: unknown;
16
16
  constructor(options: NotFoundOptions | undefined);
17
17
  }
18
- export declare function notFound(options: NotFoundOptions | undefined): never;
18
+ export declare function notFound(options?: NotFoundOptions): never;
19
19
  export declare function isNotFoundError(err: unknown): err is FurinNotFoundError;
@@ -1,2 +1,11 @@
1
- /** Positive when a is more specific: literal > parameter > catch-all. */
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;