@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.
Files changed (85) hide show
  1. package/dist/adapter/runtime-build.d.ts +7 -3
  2. package/dist/adapter/vercel.js +31 -6
  3. package/dist/build/client.d.ts +1 -1
  4. package/dist/build/entry-template.d.ts +3 -12
  5. package/dist/build/entry-template.ts +3 -15
  6. package/dist/build/hydrate.d.ts +6 -1
  7. package/dist/build/index.d.ts +1 -1
  8. package/dist/build/index.js +565 -401
  9. package/dist/build/route-metadata.d.ts +2 -2
  10. package/dist/build/route-types.d.ts +1 -1
  11. package/dist/build/types.d.ts +10 -4
  12. package/dist/cli/index.js +594 -422
  13. package/dist/client/chunks/{client-xy6g38kx.js → client-a7spxfnn.js} +24 -5
  14. package/dist/client/chunks/{client-rjhxgt64.js → client-d9v49jwz.js} +1 -1
  15. package/dist/client/chunks/{client-k29262a4.js → client-rdxyrw11.js} +1 -1
  16. package/dist/client/define-route.d.ts +14 -0
  17. package/dist/client/internal/runtime-types.d.ts +8 -0
  18. package/dist/client/link.js +3 -3
  19. package/dist/client/router/link-utils.d.ts +3 -2
  20. package/dist/client/router/search/index.js +2 -2
  21. package/dist/client/router/types.d.ts +9 -3
  22. package/dist/client.js +22 -6
  23. package/dist/config.d.ts +4 -0
  24. package/dist/config.js +4 -1
  25. package/dist/define-route.d.ts +53 -12
  26. package/dist/furin.d.ts +13 -3
  27. package/dist/furin.js +766 -614
  28. package/dist/plugin/route-config.d.ts +3 -3
  29. package/dist/plugin/route-manifest.d.ts +46 -0
  30. package/dist/plugin/route-tree.d.ts +13 -29
  31. package/dist/routes.d.ts +2 -2
  32. package/dist/server/dev/runtime.d.ts +2 -1
  33. package/dist/server/internal.d.ts +6 -0
  34. package/dist/server/internal.js +57 -76
  35. package/dist/server/registrations.d.ts +4 -2
  36. package/dist/server/router/defined-route.d.ts +4 -0
  37. package/dist/server/router/discovery.d.ts +14 -4
  38. package/dist/server/router/hmr.d.ts +12 -12
  39. package/dist/server/router/patterns.d.ts +4 -12
  40. package/dist/server/router/types.d.ts +16 -1
  41. package/dist/server/static-export.js +88 -120
  42. package/dist/server/sync/drizzle/index.d.ts +8 -10
  43. package/dist/shared/route-specificity.d.ts +10 -1
  44. package/package.json +3 -6
  45. package/src/adapter/package.ts +11 -37
  46. package/src/adapter/runtime-build.ts +5 -4
  47. package/src/adapter/static.ts +1 -1
  48. package/src/adapter/vercel.ts +2 -1
  49. package/src/build/client.ts +3 -3
  50. package/src/build/discover-pages-process.ts +1 -1
  51. package/src/build/elysia-aot.ts +2 -2
  52. package/src/build/entry-template.ts +3 -15
  53. package/src/build/hydrate.ts +12 -6
  54. package/src/build/index.ts +19 -9
  55. package/src/build/route-metadata.ts +15 -8
  56. package/src/build/route-types.ts +18 -43
  57. package/src/build/types.ts +12 -5
  58. package/src/cli/config.ts +6 -0
  59. package/src/cli/index.ts +30 -14
  60. package/src/client/define-route.ts +29 -4
  61. package/src/client/internal/runtime-types.ts +8 -0
  62. package/src/client/router/link-utils.ts +16 -8
  63. package/src/client/router/types.ts +40 -14
  64. package/src/config.ts +5 -0
  65. package/src/define-route.ts +85 -16
  66. package/src/furin.ts +31 -7
  67. package/src/plugin/dev-routes.ts +8 -17
  68. package/src/plugin/route-config.ts +77 -62
  69. package/src/plugin/route-manifest.ts +437 -0
  70. package/src/plugin/route-modules.ts +6 -1
  71. package/src/plugin/route-registry.ts +7 -21
  72. package/src/plugin/route-tree.ts +71 -181
  73. package/src/routes.ts +2 -2
  74. package/src/server/dev/runtime.ts +16 -22
  75. package/src/server/internal.ts +4 -1
  76. package/src/server/registrations.ts +5 -2
  77. package/src/server/render/static-params.ts +2 -10
  78. package/src/server/router/defined-route.ts +8 -0
  79. package/src/server/router/discovery.ts +237 -196
  80. package/src/server/router/hmr.ts +45 -63
  81. package/src/server/router/patterns.ts +41 -117
  82. package/src/server/router/types.ts +17 -1
  83. package/src/server/sync/drizzle/index.ts +18 -19
  84. package/src/shared/route-specificity.ts +34 -2
  85. package/src/shared/utils/index.ts +1 -1
@@ -36,18 +36,42 @@ type SegmentMatches<
36
36
  ? true
37
37
  : false;
38
38
 
39
- /** Mirrors the router: `:param` matches one non-empty segment, `*` the rest. */
39
+ /** An optional `:param?` segment followed by `Rest`: skip it, or let it take one segment. */
40
+ type OptionalSegmentMatches<Rest extends string, Path extends string> =
41
+ PatternMatches<Rest, Path> extends true
42
+ ? true
43
+ : Path extends `${infer PathHead}/${infer PathRest}`
44
+ ? PathHead extends ""
45
+ ? false
46
+ : PatternMatches<Rest, PathRest>
47
+ : false;
48
+
49
+ /**
50
+ * Mirrors the router: `:param` matches one non-empty segment, `:param?` one
51
+ * or none, `*` the rest. `Head` is always a single segment: `${infer Head}/`
52
+ * stops at the first slash.
53
+ */
40
54
  type PatternMatches<Pattern extends string, Path extends string> = Pattern extends "*"
41
55
  ? true
42
56
  : Pattern extends `${infer Head}/${infer Rest}`
43
- ? Path extends `${infer PathHead}/${infer PathRest}`
44
- ? SegmentMatches<Head, PathHead> extends true
45
- ? PatternMatches<Rest, PathRest>
46
- : false
47
- : false
48
- : Path extends `${string}/${string}`
49
- ? false
50
- : SegmentMatches<Pattern, Path>;
57
+ ? Head extends `:${string}?`
58
+ ? OptionalSegmentMatches<Rest, Path>
59
+ : Path extends `${infer PathHead}/${infer PathRest}`
60
+ ? SegmentMatches<Head, PathHead> extends true
61
+ ? PatternMatches<Rest, PathRest>
62
+ : false
63
+ : Rest extends `${string}/${string}`
64
+ ? false
65
+ : Rest extends `:${string}?`
66
+ ? SegmentMatches<Head, Path>
67
+ : false
68
+ : Pattern extends `:${string}?`
69
+ ? Path extends `${string}/${string}`
70
+ ? false
71
+ : true
72
+ : Path extends `${string}/${string}`
73
+ ? false
74
+ : SegmentMatches<Pattern, Path>;
51
75
 
52
76
  type MatchingPattern<Path extends string> = {
53
77
  [Pattern in RoutePattern]: PatternMatches<Pattern, Path> extends true ? Pattern : never;
@@ -177,11 +201,13 @@ export type PreloadStrategy = false | "intent" | "viewport" | "render";
177
201
 
178
202
  type LinkPathParamKeys<Path extends string> = Path extends `${infer Segment}/${infer Rest}`
179
203
  ? LinkPathParamKeys<Segment> | LinkPathParamKeys<Rest>
180
- : Path extends `:${infer Key}`
181
- ? Key
182
- : Path extends "*"
183
- ? "*"
184
- : never;
204
+ : Path extends `:${string}?`
205
+ ? never
206
+ : Path extends `:${infer Key}`
207
+ ? Key
208
+ : Path extends "*"
209
+ ? "_splat"
210
+ : never;
185
211
 
186
212
  type LinkParams<To extends RouteTo> = [To] extends [RoutePattern]
187
213
  ? LinkPathParamKeys<To> extends never
package/src/config.ts CHANGED
@@ -45,6 +45,7 @@ export interface StaticExportConfig {
45
45
  }
46
46
 
47
47
  const compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
48
+ const routeStyleSchema = t.Union([t.Literal("nextjs"), t.Literal("tanstack")]);
48
49
 
49
50
  export const configSchema = t.Object({
50
51
  /**
@@ -57,6 +58,7 @@ export const configSchema = t.Object({
57
58
  t.Object({
58
59
  pagesDir: t.String(),
59
60
  prefix: t.Optional(t.String()),
61
+ style: routeStyleSchema,
60
62
  })
61
63
  )
62
64
  ),
@@ -80,6 +82,7 @@ export const configSchema = t.Object({
80
82
  * Packages declaring `sideEffects: false` are optimized automatically.
81
83
  */
82
84
  optimizeImports: t.Optional(t.Array(t.String())),
85
+ /** Single-app build: its pages directory, with `style`. Prefer `apps` or the server entry's mounts. */
83
86
  pagesDir: t.Optional(t.String()),
84
87
  /**
85
88
  * Module preloading. `routeChunks` (default true) makes `<HeadContent />`
@@ -95,6 +98,8 @@ export const configSchema = t.Object({
95
98
  serverEntry: t.Optional(t.String()),
96
99
  /** Emit private server source maps for error-tool uploads. Off by default. */
97
100
  serverSourceMaps: t.Optional(t.Boolean()),
101
+ /** File-routing style of `pagesDir`: `"nextjs"` or `"tanstack"`. */
102
+ style: t.Optional(routeStyleSchema),
98
103
  static: t.Optional(
99
104
  t.Object({
100
105
  basePath: t.Optional(t.String()),
@@ -5,6 +5,8 @@ import type { HeadOptions, RenderingMode } from "./client.ts";
5
5
  import { applySchemaDefaults, coerceRouteInput } from "./server/router/schemas.ts";
6
6
  import type { FurinSchema, FurinUnwrap, FurinUnwrapInput } from "./shared/elysia-contract.ts";
7
7
  import { getSchemaValidator, isTypeBoxObjectSchema } from "./shared/elysia-contract.ts";
8
+ import type { ErrorComponent } from "./shared/error.ts";
9
+ import type { NotFoundComponent } from "./shared/not-found.ts";
8
10
  import type { RemountDependency, RemountDeps } from "./shared/page-key.ts";
9
11
 
10
12
  type NoFields = NonNullable<unknown>;
@@ -344,22 +346,45 @@ function routeHandler(route: FurinRouteKey) {
344
346
  };
345
347
  }
346
348
 
349
+ interface ElysiaPathParams {
350
+ [name: string]: string | undefined;
351
+ }
352
+
353
+ /**
354
+ * Elysia names a catch-all `*`; routes read it as `_splat`, as in TanStack
355
+ * Start. A transform hook runs before validation, so params schemas see it.
356
+ */
357
+ function renameSplatParam(context: { params: ElysiaPathParams | undefined }): void {
358
+ if (context.params !== undefined && "*" in context.params) {
359
+ const { "*": splat, ...params } = context.params;
360
+ context.params = { ...params, _splat: splat };
361
+ }
362
+ }
363
+
347
364
  function registerPlain(route: FurinRouteKey) {
348
- return new Elysia().get("", routeHandler(route));
365
+ return new Elysia().get("", { transform: renameSplatParam }, routeHandler(route));
349
366
  }
350
367
 
351
368
  function registerSchema<
352
369
  ParamsSchema extends FurinSchema,
353
370
  QuerySchema extends FurinSchema | undefined,
354
371
  >(route: FurinRouteKey, paramsSchema: ParamsSchema, querySchema: QuerySchema) {
355
- return new Elysia().get("", { params: paramsSchema, query: querySchema }, routeHandler(route));
372
+ return new Elysia().get(
373
+ "",
374
+ { params: paramsSchema, query: querySchema, transform: renameSplatParam },
375
+ routeHandler(route)
376
+ );
356
377
  }
357
378
 
358
379
  function registerQuery<QuerySchema extends FurinSchema>(
359
380
  route: FurinRouteKey,
360
381
  querySchema: QuerySchema
361
382
  ) {
362
- return new Elysia().get("", { query: querySchema }, routeHandler(route));
383
+ return new Elysia().get(
384
+ "",
385
+ { query: querySchema, transform: renameSplatParam },
386
+ routeHandler(route)
387
+ );
363
388
  }
364
389
 
365
390
  function schemaValues(value: unknown): SchemaValues {
@@ -622,14 +647,16 @@ type KindCheck<
622
647
  ? ValidComponent
623
648
  : FurinTypeError<
624
649
  Terminal extends "page"
625
- ? "this route file is a layout (_route): finish it with layout()"
626
- : "this route file is a page: finish it with page(); layouts live in _route files"
650
+ ? "this route file is a layout: finish it with layout()"
651
+ : "this route file is a page: finish it with page()"
627
652
  >;
628
653
 
629
654
  interface ChainRuntime {
655
+ errorComponent: ErrorComponent | undefined;
630
656
  head: unknown;
631
657
  loader: unknown;
632
658
  metadata: RouteMetadata;
659
+ notFoundComponent: NotFoundComponent | undefined;
633
660
  paramsSchema: FurinSchema | undefined;
634
661
  querySchema: FurinSchema | undefined;
635
662
  requestLoader: unknown;
@@ -638,19 +665,33 @@ interface ChainRuntime {
638
665
  // Named stages keep compile errors readable, e.g. "Property 'staticParams'
639
666
  // does not exist on type 'SsrRouteStage<...>'".
640
667
 
668
+ /** `.error()` / `.notFound()` keep the stage they are called on. */
669
+ type BoundaryMethods = "error" | "notFound";
670
+
671
+ interface BoundaryStage<Stage> {
672
+ error: (component: ErrorComponent) => Stage;
673
+ notFound: (component: NotFoundComponent) => Stage;
674
+ }
675
+
641
676
  /** SSR routes render per request: `staticParams()` needs mode `ssg` or `isr`. */
642
- interface SsrRouteStage<State extends ChainState> extends Omit<RouteChain<State>, "staticParams"> {}
677
+ interface SsrRouteStage<State extends ChainState>
678
+ extends Omit<RouteChain<State>, "staticParams" | BoundaryMethods>,
679
+ BoundaryStage<SsrRouteStage<State>> {}
643
680
 
644
681
  /** `staticParams()` must come first and only once, before `requestLoader()`. */
645
682
  interface StaticParamsClosedStage<State extends ChainState>
646
- extends Omit<RouteChain<State>, "staticParams"> {}
683
+ extends Omit<RouteChain<State>, "staticParams" | BoundaryMethods>,
684
+ BoundaryStage<StaticParamsClosedStage<State>> {}
647
685
 
648
686
  /** After `loader()`: attach `head()` or finish with `page()`/`layout()`. */
649
687
  interface LoadedRouteStage<State extends ChainState>
650
- extends Pick<RouteChain<State>, "head" | "layout" | "page"> {}
688
+ extends Pick<RouteChain<State>, "head" | "layout" | "page">,
689
+ BoundaryStage<LoadedRouteStage<State>> {}
651
690
 
652
691
  /** `head()` metadata is page-only: a headed route can only finish with `page()`. */
653
- interface HeadedPageStage<State extends ChainState> extends Pick<RouteChain<State>, "page"> {}
692
+ interface HeadedPageStage<State extends ChainState>
693
+ extends Pick<RouteChain<State>, "page">,
694
+ BoundaryStage<HeadedPageStage<State>> {}
654
695
 
655
696
  type ConfiguredStage<State extends ChainState> = State["mode"] extends infer Mode
656
697
  ? Mode extends "ssr"
@@ -669,6 +710,8 @@ type ElysiaOfSchemas<Schemas> = Schemas extends {
669
710
 
670
711
  type RouteTerminal<State extends ChainState> = {
671
712
  __type: "FURIN_ROUTE";
713
+ errorComponent: ErrorComponent | undefined;
714
+ notFoundComponent: NotFoundComponent | undefined;
672
715
  head:
673
716
  | Head<State["params"], State["query"], State["parentData"], State["data"], State["mode"]>
674
717
  | undefined;
@@ -745,9 +788,20 @@ function schemaFields(paramsSchema: FurinSchema | undefined, querySchema: FurinS
745
788
  }
746
789
 
747
790
  function terminalFields(runtime: ChainRuntime) {
748
- const { head, loader, metadata, paramsSchema, querySchema, requestLoader } = runtime;
791
+ const {
792
+ errorComponent,
793
+ head,
794
+ loader,
795
+ metadata,
796
+ notFoundComponent,
797
+ paramsSchema,
798
+ querySchema,
799
+ requestLoader,
800
+ } = runtime;
749
801
  return {
750
802
  __type: "FURIN_ROUTE" as const,
803
+ errorComponent,
804
+ notFoundComponent,
751
805
  mode: metadata.mode,
752
806
  revalidate: metadata.revalidate,
753
807
  remountDeps: metadata.remountDeps,
@@ -767,6 +821,19 @@ class RouteChain<State extends ChainState> {
767
821
  this.runtime = runtime;
768
822
  }
769
823
 
824
+ /**
825
+ * TanStack style: renders in place of this route (in its parent's outlet)
826
+ * when it or a route below it fails, as `errorComponent` does.
827
+ */
828
+ error(component: ErrorComponent): this {
829
+ return new RouteChain<State>({ ...this.runtime, errorComponent: component }) as this;
830
+ }
831
+
832
+ /** TanStack style: renders when this route or one below it calls `notFound()`. */
833
+ notFound(component: NotFoundComponent): this {
834
+ return new RouteChain<State>({ ...this.runtime, notFoundComponent: component }) as this;
835
+ }
836
+
770
837
  requestLoader<Data extends RequestLoaderData>(
771
838
  requestLoader: RequestLoader<State["params"], State["query"], Data>
772
839
  ): StaticParamsClosedStage<WithState<State, { requestData: Data }>> {
@@ -840,9 +907,11 @@ interface ConfigOptions {
840
907
  function configure(options: RouteMetadata & ConfigOptions): unknown {
841
908
  assertStaticParamsOutsideConfig(options);
842
909
  return new RouteChain({
910
+ errorComponent: undefined,
843
911
  head: undefined,
844
912
  loader: undefined,
845
913
  metadata: options,
914
+ notFoundComponent: undefined,
846
915
  paramsSchema: options.params,
847
916
  querySchema: options.query,
848
917
  requestLoader: undefined,
@@ -850,7 +919,7 @@ function configure(options: RouteMetadata & ConfigOptions): unknown {
850
919
  }
851
920
 
852
921
  /**
853
- * Stage for `pages/root.tsx` — the document shell has no layout above it, so
922
+ * Stage for the root layout — the document shell has no layout above it, so
854
923
  * `config()` requires only `mode` (the TanStack `createRootRoute` analogue).
855
924
  */
856
925
  class UnconfiguredRootRoute {
@@ -906,10 +975,10 @@ class UnconfiguredRootRoute {
906
975
  }
907
976
 
908
977
  /**
909
- * First stage of the builder, `defineRoute("/board/[boardId]")`: `config()` is
978
+ * First stage of the builder, `defineRoute("/board/$boardId/")`: `config()` is
910
979
  * MANDATORY and declares at least `mode`. The generated `FileRoutes` entry
911
980
  * supplies the parent layout, the path params and the terminal (`layout()` for
912
- * `_route` files, `page()` otherwise), so `config()` takes no `layout` and
981
+ * layout files, `page()` otherwise), so `config()` takes no `layout` and
913
982
  * `params` only refines the path params.
914
983
  */
915
984
  class UnconfiguredFileRoute<Entry> {
@@ -967,9 +1036,9 @@ class UnconfiguredFileRoute<Entry> {
967
1036
  }
968
1037
 
969
1038
  /**
970
- * `defineRoute(id)` keys the route by its file id (the app's prefix, then the
971
- * path under `pagesDir` with brackets and groups, `/index` dropped, layouts
972
- * ending in `/_route`) and reads its parent from the generated `FileRoutes`.
1039
+ * `defineRoute(id)` keys the route by its TanStack Start id (the app's
1040
+ * prefix, then `/board/$boardId/` for an index, `/board` for a layout, in
1041
+ * both routing styles) and reads its parent from the generated `FileRoutes`.
973
1042
  * The id is type-only: the runtime chain comes from the pages tree.
974
1043
  */
975
1044
  export function defineRoute<Id extends FileRouteId>(
package/src/furin.ts CHANGED
@@ -2,6 +2,7 @@ import { dirname, resolve } from "node:path";
2
2
  import { type AnyElysia, Elysia, NotFound } from "elysia";
3
3
  import type { RequestLogger } from "evlog";
4
4
  import { FURIN_RENDER_DECORATOR, type FurinNativeRouteContext } from "./define-route.ts";
5
+ import type { RouteStyle } from "./plugin/route-manifest.ts";
5
6
  import { consumePendingInvalidations } from "./server/cache/invalidation.ts";
6
7
  import type { PageCacheAdapter } from "./server/cache/page-cache.ts";
7
8
  import { setPageCacheAdapter } from "./server/cache/page-cache-state.ts";
@@ -88,6 +89,12 @@ type FurinApplication<App extends AnyElysia> =
88
89
  >
89
90
  : never;
90
91
 
92
+ /** Each style's conventional pages directory: Next.js `app/`, TanStack Start `routes/`. */
93
+ const DEFAULT_PAGES_DIRS: { [Style in RouteStyle]: string } = {
94
+ nextjs: "src/app",
95
+ tanstack: "src/routes",
96
+ };
97
+
91
98
  /** Options for the {@link furin} plugin. */
92
99
  export interface FurinOptions {
93
100
  /**
@@ -125,6 +132,7 @@ export interface FurinOptions {
125
132
  * process-local cache.
126
133
  */
127
134
  pageCache?: PageCacheAdapter;
135
+ /** Defaults to `src/app` in the `nextjs` style and `src/routes` in the `tanstack` style. */
128
136
  pagesDir?: string;
129
137
  /**
130
138
  * Full physical mount path of this app, e.g. `"/admin"`. All pages,
@@ -137,6 +145,13 @@ export interface FurinOptions {
137
145
  * two prefixes, throws.
138
146
  */
139
147
  prefix?: string;
148
+ /**
149
+ * File-routing convention of `pagesDir`: `"nextjs"` (App Router: `layout.tsx`,
150
+ * `page.tsx`, `[id]`, `error.tsx`) or `"tanstack"` (TanStack Start:
151
+ * `__root.tsx`, `route.tsx`, `$id`, flat `a.$b.tsx`). Both key
152
+ * `defineRoute(id)` with TanStack Start ids.
153
+ */
154
+ style: RouteStyle;
140
155
  /**
141
156
  * Configures Furin's sync event stream with the required adapter. The
142
157
  * optional `path` defaults to `/_furin/sync`. Omit this option or pass
@@ -220,13 +235,14 @@ async function createFurinApp(options: FurinOptions): Promise<{
220
235
  logger,
221
236
  pageCache,
222
237
  pagesDir,
238
+ style,
223
239
  sync,
224
240
  } = options;
225
241
  const prefix = normalizePrefix(options.prefix);
226
242
  const cwd = process.cwd();
227
243
  // In a deployed binary the cwd-resolved pagesDir may differ from the build
228
244
  // machine's; the compile context is found by the (stable) declared prefix.
229
- const paramPagesDir = resolve(cwd, pagesDir ?? "src/pages");
245
+ const paramPagesDir = resolve(cwd, pagesDir ?? DEFAULT_PAGES_DIRS[style]);
230
246
  const ctx = getCompileContext(paramPagesDir, prefix);
231
247
  const resolvedPagesDir = ctx?.rootPath ? dirname(ctx.rootPath) : paramPagesDir;
232
248
  const normalizedPagesDir = resolvedPagesDir.replaceAll("\\", "/");
@@ -270,6 +286,7 @@ async function createFurinApp(options: FurinOptions): Promise<{
270
286
  ? await (await import("./server/dev/runtime.ts")).createDevRuntime(
271
287
  instance,
272
288
  resolvedPagesDir,
289
+ style,
273
290
  modeOptions
274
291
  )
275
292
  : await createProdRuntime(instance, ctx, clientDir, modeOptions);
@@ -322,22 +339,28 @@ const mountedPrefixes = new WeakMap<AnyElysia, Map<string, FurinInstance>>();
322
339
  *
323
340
  * ```ts
324
341
  * new Elysia()
325
- * .use(await furin({ pagesDir: "./src/pages" }))
326
- * .use(await furin({ pagesDir: "./src/admin", prefix: "/admin" }))
342
+ * .use(await furin({ style: "tanstack" }))
343
+ * .use(await furin({ pagesDir: "./src/admin", prefix: "/admin", style: "nextjs" }))
327
344
  * .listen(3000)
328
345
  * ```
329
346
  */
330
- export async function furin(options?: FurinOptions) {
347
+ export async function furin(options: FurinOptions) {
348
+ if (options.style !== "nextjs" && options.style !== "tanstack") {
349
+ throw new Error(
350
+ `[furin] furin() requires style: "nextjs" or "tanstack", received ${JSON.stringify(options.style)}.`
351
+ );
352
+ }
331
353
  const registration = {
332
- pagesDir: options?.pagesDir ?? "src/pages",
333
- prefix: normalizePrefix(options?.prefix),
354
+ pagesDir: options.pagesDir ?? DEFAULT_PAGES_DIRS[options.style],
355
+ prefix: normalizePrefix(options.prefix),
356
+ style: options.style,
334
357
  };
335
358
  if (recordFurinRegistration(registration)) {
336
359
  // The build only discovers mounts: no runtime, nothing to mount.
337
360
  return <ParentApp extends AnyElysia>(parentApp: ParentApp) =>
338
361
  parentApp as unknown as FurinApplication<ParentApp>;
339
362
  }
340
- const { app, hasSync, instance } = await createFurinApp(options ?? {});
363
+ const { app, hasSync, instance } = await createFurinApp(options);
341
364
  let mounted = false;
342
365
  return <ParentApp extends AnyElysia>(parentApp: ParentApp): FurinApplication<ParentApp> => {
343
366
  if (mounted) {
@@ -367,6 +390,7 @@ export async function furin(options?: FurinOptions) {
367
390
 
368
391
  export { FurinErrorBoundary, FurinNotFoundBoundary } from "./client/boundaries.tsx";
369
392
  export { HeadContent, Scripts } from "./client/document.tsx";
393
+ export type { RouteStyle } from "./plugin/route-manifest.ts";
370
394
  export type { Register } from "./routes.ts";
371
395
  export type { InvalidationInput, InvalidationRule } from "./server/auto-invalidate/index.ts";
372
396
  export { furinInvalidate, revalidateTag } from "./server/auto-invalidate/index.ts";
@@ -3,7 +3,6 @@ import { dirname, relative, resolve, sep } from "node:path";
3
3
  import { type AnyElysia, Elysia } from "elysia";
4
4
  import { type FurinNativeRouteContext, getFurinRenderer } from "../define-route.ts";
5
5
  import { detectLoaderFromPath, SCRIPT_FILE_FILTER } from "../server/lang-detect.ts";
6
- import { isRouteGroup } from "../server/router/patterns.ts";
7
6
  import { routeModuleSourceVersion } from "../server/router/source-version.ts";
8
7
  import { type RouteModule, routeModuleDependencies, validateRouteParams } from "./route-modules.ts";
9
8
  import {
@@ -14,7 +13,6 @@ import {
14
13
  type RouteTreeNode,
15
14
  routeModuleSpecifier,
16
15
  routeSnapshotSourcePaths,
17
- segmentPath,
18
16
  } from "./route-tree.ts";
19
17
 
20
18
  const DEV_ROUTE_WATCHERS_SYMBOL = Symbol.for("@teyik0/furin/dev-route-watchers");
@@ -380,28 +378,21 @@ async function composableRouteApps(route: RouteFile): Promise<DevRoutesApps | un
380
378
  }
381
379
 
382
380
  async function composeRuntimeNode(node: RouteTreeNode): Promise<DevRoutesApps> {
383
- const prefix = node.name && !isRouteGroup(node.name) ? `/${segmentPath(node.name)}` : "";
384
- const { fileRoutes } = node;
385
- const [layoutApps, indexRouteApps, fileRouteApps, childApps] = await Promise.all([
381
+ const { pages, prefix } = node;
382
+ const [layoutApps, pageApps, childApps] = await Promise.all([
386
383
  node.layout ? composableRouteApps(node.layout) : undefined,
387
- node.indexRoute ? composableRouteApps(node.indexRoute) : undefined,
388
- Promise.all(fileRoutes.map((route) => composableRouteApps(route))),
384
+ Promise.all(pages.map((route) => composableRouteApps(route))),
389
385
  Promise.all(node.children.map((child) => composeRuntimeNode(child))),
390
386
  ]);
391
387
  const appScope = layoutApps?.app ?? new Elysia();
392
388
  const shellScope = layoutApps?.shell ?? new Elysia();
393
389
 
394
- if (indexRouteApps) {
395
- appScope.use(new Elysia({ prefix: "" }).use(indexRouteApps.app));
396
- shellScope.use(new Elysia({ prefix: "" }).use(indexRouteApps.shell));
397
- }
398
- for (const [index, route] of fileRoutes.entries()) {
399
- const routeApps = fileRouteApps[index];
390
+ for (const [index, route] of pages.entries()) {
391
+ const routeApps = pageApps[index];
400
392
  if (routeApps) {
401
- const segment = route.path.slice(route.path.lastIndexOf("/") + 1);
402
- appScope.use(new Elysia({ prefix: `/${segment}` }).use(routeApps.app));
393
+ appScope.use(new Elysia({ prefix: route.prefix }).use(routeApps.app));
403
394
  if (route.path !== "/*") {
404
- shellScope.use(new Elysia({ prefix: `/${segment}` }).use(routeApps.shell));
395
+ shellScope.use(new Elysia({ prefix: route.prefix }).use(routeApps.shell));
405
396
  }
406
397
  }
407
398
  }
@@ -420,7 +411,7 @@ async function composeRuntimeInstance(instance: RouteInstanceSpec): Promise<DevR
420
411
  const { registerDevPagePlugin } = await import("../server/dev-page-plugin.ts");
421
412
  registerDevPagePlugin();
422
413
  const instanceId = Bun.hash(instanceKey(instance)).toString(16);
423
- return composeRuntimeNode(buildRouteTree(instance.pagesDir, instanceId));
414
+ return composeRuntimeNode(buildRouteTree(instance, instanceId));
424
415
  }
425
416
 
426
417
  /**