@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
|
@@ -36,18 +36,42 @@ type SegmentMatches<
|
|
|
36
36
|
? true
|
|
37
37
|
: false;
|
|
38
38
|
|
|
39
|
-
/**
|
|
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
|
-
?
|
|
44
|
-
?
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 `:${
|
|
181
|
-
?
|
|
182
|
-
: Path extends
|
|
183
|
-
?
|
|
184
|
-
:
|
|
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()),
|
package/src/define-route.ts
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
|
626
|
-
: "this route file is a page: finish it with page()
|
|
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>
|
|
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>
|
|
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 {
|
|
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
|
|
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/
|
|
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
|
-
*
|
|
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
|
|
971
|
-
*
|
|
972
|
-
*
|
|
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 ??
|
|
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({
|
|
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
|
|
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
|
|
333
|
-
prefix: normalizePrefix(options
|
|
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";
|
package/src/plugin/dev-routes.ts
CHANGED
|
@@ -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
|
|
384
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
395
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
414
|
+
return composeRuntimeNode(buildRouteTree(instance, instanceId));
|
|
424
415
|
}
|
|
425
416
|
|
|
426
417
|
/**
|