@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
@@ -1,4 +1,4 @@
1
- import type { HeadOptions, MetaDescriptor } from "../../client.ts";
1
+ import type { MetaDescriptor } from "../../client.ts";
2
2
 
3
3
  export function extractTitle(meta?: MetaDescriptor[]): string | undefined {
4
4
  if (!meta) {
@@ -11,15 +11,6 @@ export function extractTitle(meta?: MetaDescriptor[]): string | undefined {
11
11
  }
12
12
  }
13
13
 
14
- export function isMetaTag(entry: MetaDescriptor): boolean {
15
- return !(
16
- "title" in entry ||
17
- "charSet" in entry ||
18
- "script:ld+json" in entry ||
19
- "tagName" in entry
20
- );
21
- }
22
-
23
14
  export function escapeHtml(str: string): string {
24
15
  return str
25
16
  .replace(/&/g, "&")
@@ -37,86 +28,6 @@ export function safeJson(value: unknown): string {
37
28
  .replace(/\u2029/g, "\\u2029");
38
29
  }
39
30
 
40
- export function renderAttrs(obj: Record<string, string | undefined>): string {
41
- const parts: string[] = [];
42
- for (const [k, v] of Object.entries(obj)) {
43
- if (v !== undefined) {
44
- parts.push(`${k}="${escapeHtml(String(v))}"`);
45
- }
46
- }
47
- return parts.join(" ");
48
- }
49
-
50
- // ---------------------------------------------------------------------------
51
- // Head injection helpers
52
- // ---------------------------------------------------------------------------
53
-
54
- export function buildMetaParts(meta: MetaDescriptor[]): string[] {
55
- const parts: string[] = [];
56
- const title = extractTitle(meta);
57
- if (title) {
58
- parts.push(`<title>${escapeHtml(title)}</title>`);
59
- }
60
- for (const m of meta) {
61
- if (isMetaTag(m)) {
62
- parts.push(`<meta ${renderAttrs(m as Record<string, string>)} />`);
63
- }
64
- if ("script:ld+json" in m) {
65
- parts.push(`<script type="application/ld+json">${safeJson(m["script:ld+json"])}</script>`);
66
- }
67
- }
68
- return parts;
69
- }
70
-
71
- export function buildLinkParts(links: NonNullable<HeadOptions["links"]>): string[] {
72
- return links.map((link) => `<link ${renderAttrs(link)} />`);
73
- }
74
-
75
- export function buildScriptParts(scripts: NonNullable<HeadOptions["scripts"]>): string[] {
76
- return scripts.map((script) => {
77
- const { children, ...rest } = script;
78
- const attrs = renderAttrs(rest as Record<string, string | undefined>);
79
- if (children) {
80
- return `<script ${attrs}>${children}</script>`;
81
- }
82
- return `<script ${attrs}></script>`;
83
- });
84
- }
85
-
86
- export function buildStyleParts(styles: NonNullable<HeadOptions["styles"]>): string[] {
87
- return styles.map((style) => {
88
- const typeAttr = style.type ? ` type="${escapeHtml(style.type)}"` : "";
89
- return `<style${typeAttr}>${style.children}</style>`;
90
- });
91
- }
92
-
93
- /**
94
- * Builds the string to inject into the <!--ssr-head--> placeholder.
95
- * Handles title, meta tags, links, inline scripts, and inline styles from
96
- * the page's `head()` function. CSS is handled by Bun (imported in user files).
97
- */
98
- export function buildHeadInjection(headData: HeadOptions | undefined): string {
99
- const parts: string[] = [];
100
-
101
- if (headData?.meta) {
102
- parts.push(...buildMetaParts(headData.meta));
103
- }
104
-
105
- if (headData?.links) {
106
- parts.push(...buildLinkParts(headData.links));
107
- }
108
-
109
- if (headData?.scripts) {
110
- parts.push(...buildScriptParts(headData.scripts));
111
- }
112
-
113
- if (headData?.styles) {
114
- parts.push(...buildStyleParts(headData.styles));
115
- }
116
-
117
- return parts.length > 0 ? `\n ${parts.join("\n ")}\n` : "";
118
- }
119
-
120
31
  export function generateIndexHtml(): string {
121
32
  return `<!DOCTYPE html>
122
33
  <html lang="en">
@@ -1,14 +1,18 @@
1
1
  import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
2
2
  import type { HeadOptions, RenderingMode } from "../../client.ts";
3
+ import type { ErrorComponent } from "../../shared/error.ts";
4
+ import type { NotFoundComponent } from "../../shared/not-found.ts";
3
5
  import type { RemountDependency } from "../../shared/page-key.ts";
4
6
  interface DefinedRouteTerminal {
5
7
  __type: "FURIN_ROUTE";
6
8
  component: (...args: never[]) => React.ReactNode;
7
9
  elysia: object;
10
+ errorComponent?: ErrorComponent;
8
11
  head?: (...args: never[]) => HeadOptions;
9
12
  layout?: (...args: never[]) => React.ReactNode;
10
13
  loader?: (...args: never[]) => unknown;
11
14
  mode?: RenderingMode;
15
+ notFoundComponent?: NotFoundComponent;
12
16
  page?: (...args: never[]) => React.ReactNode;
13
17
  remountDeps?: (context: never) => readonly RemountDependency[];
14
18
  requestLoader?: (...args: never[]) => unknown;
@@ -1,6 +1,7 @@
1
1
  import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
2
+ import { type ManifestRoute, type RouteInstanceSpec, type RouteManifest, type RouteStyle } from "../../plugin/route-manifest.ts";
2
3
  import { type CompileContext } from "../internal.ts";
3
- import type { ResolvedRoute, RootLayout } from "./types.ts";
4
+ import type { ResolvedLayout, ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
4
5
  export declare function isModuleNotFoundError(err: unknown): boolean;
5
6
  export declare function annotateScannedRequestKeys(routes: ResolvedRoute[]): Promise<void>;
6
7
  /** @internal Exported for unit testing. */
@@ -10,9 +11,18 @@ export declare function loadProdRoutes(ctx: CompileContext): {
10
11
  routes: ResolvedRoute[];
11
12
  };
12
13
  export declare function invalidNestedLayoutError(layoutPath: string): Error;
13
- export declare function scanPages(pagesDir: string): Promise<{
14
+ /** Layouts wrapping a manifest route, shallow → deep, the root excluded. */
15
+ export declare function manifestLayouts(manifest: RouteManifest, route: ManifestRoute): ResolvedLayout[];
16
+ export declare function scanPages(instance: RouteInstanceSpec): Promise<{
14
17
  root: RootLayout;
15
18
  routes: ResolvedRoute[];
16
19
  }>;
17
- export declare function scanRootLayout(pagesDir: string): Promise<RootLayout>;
18
- export declare function getSourceModuleCandidates(dir: string, name: string): string[];
20
+ export declare function scanRootLayout(manifest: RouteManifest, pagesDir: string, style: RouteStyle): Promise<RootLayout>;
21
+ /**
22
+ * TanStack-style boundaries come from `.error()` / `.notFound()` on the
23
+ * routes themselves. A route's boundary sits in its parent's outlet, so it
24
+ * also catches the route's own failure: depth = its chain index - 1. The
25
+ * root's sits inside the root layout (depth 0). `path` is the route file, so
26
+ * only the root's boundary is the root directory's.
27
+ */
28
+ export declare function routeDefinedBoundaries(root: RootLayout, routeChain: readonly RuntimeRoute[], page: RuntimePage, pagePath: string): SegmentBoundary[];
@@ -13,14 +13,15 @@ type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
13
13
  export declare function importStampedRouteModule(path: string, resolveImport: RouteModuleImport): Promise<CompiledModule>;
14
14
  export declare function invalidateStampedRouteModules(): void;
15
15
  /**
16
- * Re-imports edited intermediate layout _route.tsx files with a versioned
17
- * module identity, then patches the layout/loader references on the existing
18
- * route-chain objects.
16
+ * Re-imports the page's layouts (`layoutPaths`, shallow → deep, as the route
17
+ * manifest lists them) with a versioned module identity, then patches the
18
+ * layout/loader references on the existing route-chain objects. `chain[0]`
19
+ * is the root, so layout `i` patches `chain[i + 1]`.
19
20
  *
20
21
  * The optional `importFn` parameter exists only for unit testing. In production
21
22
  * it defaults to the real `import()`.
22
23
  */
23
- export declare function refreshLayoutChain(chain: RuntimeRoute[], pagePath: string, rootPath: string, importFn: ((specifier: string) => Promise<CompiledModule>) | undefined): Promise<void>;
24
+ export declare function refreshLayoutChain(chain: RuntimeRoute[], layoutPaths: readonly string[], importFn: ((specifier: string) => Promise<CompiledModule>) | undefined): Promise<void>;
24
25
  /**
25
26
  * Rebuilds a `ResolvedRoute` from freshly-imported `page` and `chain` so that
26
27
  * `mode` reflects the CURRENT contents of the page module — not the value
@@ -54,16 +55,15 @@ export declare function resolveCurrentDevRoute(route: ResolvedRoute, root: RootL
54
55
  export declare const developmentPagePorts: PagePorts;
55
56
  /**
56
57
  * @internal Lists every source file whose contents can affect the render
57
- * output for a given page: the page itself, every intermediate `_route.*`
58
- * between the page and the pages root, `root.tsx`, and their local imports.
58
+ * output for a given page: the page itself, its layouts, the root layout,
59
+ * and their local imports.
59
60
  *
60
61
  * Only paths that EXIST on disk are returned. `isDevLoaderCacheValid` treats
61
62
  * a `statSync` throw as "invalid" (conservative on missing files), so listing
62
- * non-authored extension candidates here would force a permanent cache MISS
63
- * for every nested route — silently disabling the dev ISR/SSG cache for any
64
- * page in a subdirectory. Renames and deletions of TRACKED deps are still
65
- * detected: the path that previously existed will then `statSync`-throw on
66
- * the next read and yield the same conservative miss.
63
+ * missing files here would force a permanent cache MISS. Renames and
64
+ * deletions of TRACKED deps are still detected: the path that previously
65
+ * existed will then `statSync`-throw on the next read and yield the same
66
+ * conservative miss.
67
67
  */
68
- export declare function computeRouteDependencies(pagePath: string, rootPath: string): string[];
68
+ export declare function computeRouteDependencies(pagePath: string, rootPath: string, layoutPaths: readonly string[]): string[];
69
69
  export {};
@@ -1,26 +1,18 @@
1
1
  import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
2
2
  import type { ResolvedRoute } from "./types.ts";
3
3
  export { compareRouteSpecificity } from "../../shared/route-specificity.ts";
4
- export declare function collectIntermediateLayoutDirs(pagePath: string, rootPath: string): string[];
5
4
  export declare function resolveRouteRevalidate(page: RuntimePage): number | undefined;
6
5
  export declare function resolveDocumentMode(route: ResolvedRoute): "ssr" | "ssg" | "isr";
7
6
  export declare function resolveDocumentRevalidate(route: ResolvedRoute): number | undefined;
8
7
  export declare function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr";
9
- export interface DynamicRouteSegment {
10
- catchAll: boolean;
11
- name: string;
12
- }
13
- export declare function parseDynamicRouteSegment(segment: string, sourcePath: string | undefined): DynamicRouteSegment | undefined;
14
- export declare function routeSegmentToPattern(segment: string): string;
15
- export declare function isRouteGroup(segment: string): boolean;
16
- export declare function routePatternKey(pattern: string): string;
17
- export declare function filePathToPattern(path: string): string;
8
+ /** Param name of a catch-all segment (`*` in patterns), as in TanStack Start. */
9
+ export declare const SPLAT_PARAM = "_splat";
18
10
  export declare function escapeRegExp(value: string): string;
19
11
  /**
20
12
  * Unanchored regex source for a route pattern: literal characters (e.g. dots
21
13
  * in `v1.0`) are escaped, each `:param` becomes `sources.param` and `*`
22
- * becomes `sources.catchAll`. `paramNames` lists them in order (`*` for the
23
- * catch-all).
14
+ * becomes `sources.catchAll`. `paramNames` lists them in order (`_splat` for
15
+ * the catch-all).
24
16
  */
25
17
  export declare function routePatternRegexSource(pattern: string, sources: {
26
18
  catchAll: string;
@@ -21,18 +21,33 @@ export interface SegmentBoundary {
21
21
  * can't survive the server→client boundary.
22
22
  */
23
23
  errorPath?: string;
24
+ /**
25
+ * TanStack style: the components are a route's `.error()` / `.notFound()`,
26
+ * read from `errorPath`'s `route` export instead of its default export.
27
+ */
28
+ fromRoute?: true;
24
29
  notFound?: NotFoundComponent;
25
30
  /** Absolute path to the `not-found.tsx` module, when present. */
26
31
  notFoundPath?: string;
27
- /** Absolute directory path. */
32
+ /**
33
+ * Absolute directory path; the route file for a `fromRoute` boundary,
34
+ * except the root's, which is the pages directory.
35
+ */
28
36
  path: string;
29
37
  }
38
+ /** A layout wrapping a page, from the route manifest. */
39
+ export interface ResolvedLayout {
40
+ path: string;
41
+ pattern: string;
42
+ }
30
43
  export interface ResolvedRoute {
31
44
  isrCache?: {
32
45
  html: string;
33
46
  generatedAt: number;
34
47
  revalidate: number;
35
48
  };
49
+ /** Layouts wrapping the page, shallow → deep, the root excluded. */
50
+ layouts: ResolvedLayout[];
36
51
  mode: "ssr" | "ssg" | "isr";
37
52
  page: RuntimePage;
38
53
  path: string;