@teyik0/furin 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (69) hide show
  1. package/README.md +14 -232
  2. package/dist/auto-invalidate/index.d.ts +4 -0
  3. package/dist/auto-invalidate/plugin.d.ts +38 -0
  4. package/dist/auto-invalidate/registry.d.ts +9 -0
  5. package/dist/auto-invalidate/runtime.d.ts +9 -0
  6. package/dist/auto-invalidate/types.d.ts +12 -0
  7. package/dist/await.d.ts +67 -0
  8. package/dist/build/index.js +2095 -185
  9. package/dist/cli/index.js +2070 -182
  10. package/dist/client.d.ts +51 -4
  11. package/dist/client.js +65 -1
  12. package/dist/deferred-ndjson.d.ts +32 -0
  13. package/dist/error.d.ts +14 -0
  14. package/dist/furin.d.ts +8 -0
  15. package/dist/furin.js +2927 -319
  16. package/dist/lang-detect.d.ts +5 -0
  17. package/dist/link.d.ts +1 -0
  18. package/dist/link.js +1453 -95
  19. package/dist/plugin/index.js +96 -25
  20. package/dist/plugin/transform-client.d.ts +2 -1
  21. package/dist/render/assemble.d.ts +32 -0
  22. package/dist/render/cache.d.ts +7 -0
  23. package/dist/render/element.d.ts +17 -1
  24. package/dist/render/index.d.ts +10 -1
  25. package/dist/render/index.ts +250 -44
  26. package/dist/render/loaders.d.ts +46 -3
  27. package/dist/render/shell.d.ts +16 -6
  28. package/dist/render/shell.ts +27 -12
  29. package/dist/router-provider.d.ts +86 -18
  30. package/dist/router.d.ts +66 -0
  31. package/dist/router.js +2909 -374
  32. package/dist/router.ts +586 -54
  33. package/dist/server-error.d.ts +12 -0
  34. package/dist/utils.d.ts +7 -0
  35. package/package.json +8 -7
  36. package/src/adapter/bun.ts +3 -3
  37. package/src/adapter/static.ts +73 -31
  38. package/src/auto-invalidate/index.ts +10 -0
  39. package/src/auto-invalidate/plugin.ts +25 -0
  40. package/src/auto-invalidate/registry.ts +60 -0
  41. package/src/auto-invalidate/runtime.ts +133 -0
  42. package/src/auto-invalidate/types.ts +16 -0
  43. package/src/await.tsx +175 -0
  44. package/src/build/client.ts +4 -8
  45. package/src/build/hydrate.ts +67 -1
  46. package/src/build/route-types.ts +29 -3
  47. package/src/build/scan-server.ts +6 -23
  48. package/src/client.ts +80 -3
  49. package/src/deferred-ndjson.ts +212 -0
  50. package/src/dev-page-plugin.ts +2 -0
  51. package/src/error.ts +18 -1
  52. package/src/furin.ts +19 -2
  53. package/src/lang-detect.ts +46 -0
  54. package/src/link.tsx +16 -3
  55. package/src/plugin/index.ts +7 -8
  56. package/src/plugin/transform-client.ts +108 -39
  57. package/src/render/assemble.ts +67 -0
  58. package/src/render/boundaries.tsx +23 -5
  59. package/src/render/cache.ts +14 -0
  60. package/src/render/default-screens.tsx +4 -11
  61. package/src/render/dev-cache.ts +5 -0
  62. package/src/render/element.tsx +26 -3
  63. package/src/render/index.ts +250 -44
  64. package/src/render/loaders.ts +219 -18
  65. package/src/render/shell.ts +27 -12
  66. package/src/router-provider.tsx +414 -122
  67. package/src/router.ts +586 -54
  68. package/src/server-error.ts +47 -0
  69. package/src/utils.ts +31 -0
package/README.md CHANGED
@@ -1,15 +1,17 @@
1
- # Furin
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/teyik0/furin/main/apps/docs/public/furin-logo.webp" alt="Furin" width="120" />
3
+ <h1>Furin</h1>
4
+ <p>React meta-framework powered by Elysia and Bun — file-based routing, SSR, SSG, ISR, and full TypeScript inference.</p>
2
5
 
3
- React meta-framework powered by Elysia and Bun, with file-based routing, nested layouts, SSR, SSG, ISR, and full TypeScript inference.
6
+ <a href="https://www.npmjs.com/package/@teyik0/furin"><img src="https://img.shields.io/npm/v/%40teyik0%2Ffurin?style=flat-square&logo=npm&color=orange" alt="npm version" /></a>
7
+ <a href="https://www.npmjs.com/package/@teyik0/furin"><img src="https://img.shields.io/npm/dm/%40teyik0%2Ffurin?style=flat-square&color=orange" alt="npm downloads" /></a>
8
+ <a href="https://github.com/teyik0/furin/blob/main/LICENSE"><img src="https://img.shields.io/github/license/teyik0/furin?style=flat-square" alt="License" /></a>
9
+ <a href="https://bun.sh"><img src="https://img.shields.io/badge/bun-%3E%3D1.3.0-f5d147?style=flat-square&logo=bun&logoColor=black" alt="Bun" /></a>
10
+ <a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-strict-3178c6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript" /></a>
11
+ <a href="https://react.review/repo/Teyik0/furin"><img src="https://react.review/api/badge/Teyik0/furin" alt="React Review" /></a>
12
+ </div>
4
13
 
5
- ## Features
6
-
7
- - file-based routing from `src/pages`
8
- - nested layouts with `_route.tsx`
9
- - SSR, SSG, and ISR through `createRoute()`
10
- - typed `params`, `query`, loader data, and `<Link />` search objects
11
- - one process for API routes and frontend pages
12
- - Bun-native development flow with Fast Refresh
14
+ ---
13
15
 
14
16
  ## Quick Start
15
17
 
@@ -26,226 +28,6 @@ For the shadcn/ui starter:
26
28
  bun create furin@latest my-app --template full
27
29
  ```
28
30
 
29
- ## First App
30
-
31
- ```tsx
32
- // src/pages/root.tsx
33
- import { createRoute } from "@teyik0/furin/client";
34
-
35
- export const route = createRoute({
36
- layout: ({ children }) => (
37
- <html lang="en">
38
- <head>
39
- <meta charSet="utf-8" />
40
- <meta content="width=device-width, initial-scale=1" name="viewport" />
41
- </head>
42
- <body>{children}</body>
43
- </html>
44
- ),
45
- });
46
- ```
47
-
48
- ```tsx
49
- // src/pages/index.tsx
50
- import { route } from "./root";
51
-
52
- export default route.page({
53
- component: () => <h1>Hello Furin</h1>,
54
- });
55
- ```
56
-
57
- ```ts
58
- // src/server.ts
59
- import { Elysia } from "elysia";
60
- import { furin } from "@teyik0/furin";
61
-
62
- const app = new Elysia()
63
- .use(await furin({ pagesDir: "./src/pages" }))
64
- .listen(3000);
65
-
66
- export type App = typeof app;
67
- ```
68
-
69
- ## Route API
70
-
71
- Use `createRoute()` for route-level configuration:
72
-
73
- - `parent`
74
- - `mode`
75
- - `revalidate`
76
- - `params`
77
- - `query`
78
- - `loader`
79
- - `layout`
80
-
81
- Use `route.page()` for page-level configuration:
82
-
83
- - `component`
84
- - `loader`
85
- - `head`
86
- - `staticParams`
87
-
88
- ## Example: Nested Layout + Typed Data
89
-
90
- ```tsx
91
- // src/pages/dashboard/_route.tsx
92
- import { createRoute } from "@teyik0/furin/client";
93
- import { route as rootRoute } from "../root";
94
-
95
- export const route = createRoute({
96
- parent: rootRoute,
97
- loader: async ({ request }) => {
98
- const user = await getSession(request);
99
- return { user };
100
- },
101
- layout: ({ children, user }) => (
102
- <div>
103
- <DashboardNav user={user} />
104
- {children}
105
- </div>
106
- ),
107
- });
108
- ```
109
-
110
- ```tsx
111
- // src/pages/dashboard/index.tsx
112
- import { route } from "./_route";
113
-
114
- export default route.page({
115
- loader: async ({ user }) => {
116
- const stats = await getDashboardStats(user.id);
117
- return { stats };
118
- },
119
- component: ({ stats, user }) => <Dashboard user={user} stats={stats} />,
120
- });
121
- ```
122
-
123
- ## Rendering Modes
124
-
125
- Rendering mode belongs to `createRoute()`:
126
-
127
- ```tsx
128
- import { createRoute } from "@teyik0/furin/client";
129
-
130
- const route = createRoute({
131
- mode: "ssg",
132
- });
133
-
134
- export default route.page({
135
- component: () => <div>Static page</div>,
136
- });
137
- ```
138
-
139
- ISR uses `revalidate` on the route:
140
-
141
- ```tsx
142
- const route = createRoute({
143
- mode: "isr",
144
- revalidate: 60,
145
- });
146
- ```
147
-
148
- Dynamic SSG pages enumerate paths with `staticParams()` on `route.page()`:
149
-
150
- ```tsx
151
- export default route.page({
152
- staticParams: async () => {
153
- const slugs = await getSlugs();
154
- return slugs.map((slug) => ({ slug }));
155
- },
156
- component: ({ post }) => <Post post={post} />,
157
- });
158
- ```
159
-
160
- ## File-Based Routing
161
-
162
- ```text
163
- src/pages/
164
- ├── root.tsx
165
- ├── index.tsx
166
- ├── blog/
167
- │ ├── _route.tsx
168
- │ ├── index.tsx
169
- │ └── [slug].tsx
170
- └── docs/
171
- ├── _route.tsx
172
- └── [...path].tsx
173
- ```
174
-
175
- - pages are regular `.tsx` files
176
- - `_route.tsx` files define layouts and route-level config
177
- - dynamic params use `[slug]`
178
- - catch-all routes use `[...path]`
179
-
180
- ## Typed Navigation
181
-
182
- Furin generates `furin-env.d.ts` so `@teyik0/furin/link` can type valid paths and route search params.
183
-
184
- ```tsx
185
- import { Link } from "@teyik0/furin/link";
186
-
187
- <Link to="/docs/rendering">Rendering</Link>;
188
- ```
189
-
190
- When a route declares a `query` schema, `<Link search={...} />` is typed from that schema.
191
-
192
- ## API Routes
193
-
194
- Elysia routes live alongside Furin pages in the same server:
195
-
196
- ```ts
197
- import { Elysia } from "elysia";
198
- import { furin } from "@teyik0/furin";
199
- import { api } from "./api";
200
-
201
- const app = new Elysia()
202
- .use(api)
203
- .use(await furin({ pagesDir: "./src/pages" }))
204
- .listen(3000);
205
- ```
206
-
207
- ## Build And Deployment
208
-
209
- Today, the implemented production build target is Bun.
210
-
211
- ```bash
212
- bunx furin build --target bun
213
- ```
214
-
215
- Output is written under:
216
-
217
- ```text
218
- .furin/build/bun/
219
- ```
220
-
221
- Compile modes:
222
-
223
- - `--compile server` keeps built client assets on disk next to the binary
224
- - `--compile embed` embeds the client assets into the binary and removes the built client directory from the target output
225
-
226
- The config type mentions `node`, `vercel`, and `cloudflare`, but those targets are planned and not implemented in the current build path.
227
-
228
- ## Workspace Commands
229
-
230
- From this monorepo root:
231
-
232
- ```bash
233
- bun run fix
234
- bun run test
235
- bun run tscheck
236
- ```
237
-
238
- For the docs app:
239
-
240
- ```bash
241
- cd apps/docs
242
- bun run dev
243
- ```
244
-
245
- ## Reference
246
-
247
- - docs site: `apps/docs`
248
- - example apps: `examples/task-manager`, `examples/weather`
249
- - core package: `packages/core`
31
+ ## Documentation
250
32
 
251
- For the full docs experience, read the site in `apps/docs`.
33
+ Full API reference, rendering modes, routing, and deployment guides at **[teyik0.github.io/furin](https://teyik0.github.io/furin/)**.
@@ -0,0 +1,4 @@
1
+ export { furinInvalidate } from "./plugin.ts";
2
+ export { AutoInvalidateRegistry, autoInvalidateRegistry } from "./registry.ts";
3
+ export { appendPendingInvalidationHeader, isSuccessfulMutationResponse, revalidateTag, runInvalidationRules, } from "./runtime.ts";
4
+ export type { InvalidationInput, InvalidationRule } from "./types.ts";
@@ -0,0 +1,38 @@
1
+ import { type AfterHandler, Elysia } from "elysia";
2
+ import type { InvalidationInput } from "./types.ts";
3
+ type AnyAfterHandleContext = Parameters<AfterHandler>[0];
4
+ export declare function furinInvalidate(): Elysia<"", {
5
+ decorator: {};
6
+ store: {};
7
+ derive: {};
8
+ resolve: {};
9
+ }, {
10
+ typebox: {};
11
+ error: {};
12
+ }, {
13
+ schema: {};
14
+ standaloneSchema: {};
15
+ macro: Partial<{
16
+ readonly invalidate: InvalidationInput;
17
+ }>;
18
+ macroFn: {
19
+ readonly invalidate: (rules: InvalidationInput) => {
20
+ readonly afterHandle: (ctx: AnyAfterHandleContext) => void;
21
+ };
22
+ };
23
+ parser: {};
24
+ response: {};
25
+ }, {}, {
26
+ derive: {};
27
+ resolve: {};
28
+ schema: {};
29
+ standaloneSchema: {};
30
+ response: {};
31
+ }, {
32
+ derive: {};
33
+ resolve: {};
34
+ schema: {};
35
+ standaloneSchema: {};
36
+ response: {};
37
+ }>;
38
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class AutoInvalidateRegistry {
2
+ private readonly pathToTags;
3
+ private readonly tagToPaths;
4
+ registerLoaderTags(urlPath: string, tags: readonly string[] | undefined): void;
5
+ pathsForTags(tags: readonly string[]): string[];
6
+ unregisterPath(urlPath: string): void;
7
+ reset(): void;
8
+ }
9
+ export declare const autoInvalidateRegistry: AutoInvalidateRegistry;
@@ -0,0 +1,9 @@
1
+ import type { Context } from "elysia";
2
+ import type { InvalidationInput } from "./types.ts";
3
+ export declare function isSuccessfulMutationResponse(ctx: Pick<Context, "set"> & {
4
+ responseValue?: unknown;
5
+ response?: unknown;
6
+ }): boolean;
7
+ export declare function appendPendingInvalidationHeader(set: Context["set"]): void;
8
+ export declare function revalidateTag(tags: string | readonly string[]): boolean;
9
+ export declare function runInvalidationRules(input: InvalidationInput): boolean;
@@ -0,0 +1,12 @@
1
+ import type { CacheTag } from "../furin.ts";
2
+ import type { RevalidateType } from "../render/route-cache.ts";
3
+ export type InvalidationRule = {
4
+ path: string;
5
+ tags?: readonly CacheTag[];
6
+ type: RevalidateType;
7
+ } | {
8
+ path?: never;
9
+ tags: readonly CacheTag[];
10
+ type?: never;
11
+ };
12
+ export type InvalidationInput = InvalidationRule | readonly InvalidationRule[];
@@ -0,0 +1,67 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * Context used to pass the caught error from `AsyncErrorBoundary` down to
4
+ * `errorElement` children so they can read it via `useAsyncError()`.
5
+ */
6
+ export declare const AsyncErrorContext: import("react").Context<unknown>;
7
+ /**
8
+ * Inside an `<Await errorElement={...}>`, returns the error that caused the
9
+ * deferred Promise to reject. Throws outside of an error-boundary subtree.
10
+ */
11
+ export declare function useAsyncError(): unknown;
12
+ /**
13
+ * Inside a resolved `<Await>`, returns the resolved value via React 19's
14
+ * `use()`. Can be used as an alternative to the render-prop children API.
15
+ *
16
+ * Must be used inside a component that is rendered as children of `<Await>`.
17
+ */
18
+ export declare function useAsyncValue<T>(): T;
19
+ export interface AwaitProps<T> {
20
+ /**
21
+ * Render-prop children: called with the resolved value once the Promise
22
+ * settles. The returned `ReactNode` is rendered inside a Suspense boundary.
23
+ *
24
+ * Marked optional here so `createElement(Await, props, renderFn)` is
25
+ * accepted by TypeScript — the 3rd argument to `createElement` becomes
26
+ * `children` at runtime and is always required for correct behaviour.
27
+ */
28
+ children?: (value: T) => ReactNode;
29
+ /**
30
+ * Rendered when the Promise rejects. Inside this subtree, `useAsyncError()`
31
+ * returns the rejection reason. When omitted the error propagates up to the
32
+ * next React error boundary.
33
+ */
34
+ errorElement?: ReactNode;
35
+ /**
36
+ * The deferred Promise to await. Passed as a prop so React's `use()` can
37
+ * suspend the boundary until it resolves. This is the same Promise object
38
+ * that the loader returned inside `defer()`.
39
+ */
40
+ resolve: Promise<T>;
41
+ }
42
+ /**
43
+ * Deferred-data boundary component. Uses React 19's `use()` to suspend the
44
+ * render until `resolve` settles, then calls the render-prop `children` with
45
+ * the resolved value.
46
+ *
47
+ * Wrap with `<Suspense fallback={…}>` to show a loading indicator while the
48
+ * Promise is pending.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * export default route.page({
53
+ * loader: () => defer({ board: "x", stats: fetchStats() }),
54
+ * component: ({ board, stats }) => (
55
+ * <div>
56
+ * <h1>{board}</h1>
57
+ * <Suspense fallback={<Spinner />}>
58
+ * <Await resolve={stats}>
59
+ * {(s) => <StatsBar stats={s} />}
60
+ * </Await>
61
+ * </Suspense>
62
+ * </div>
63
+ * ),
64
+ * });
65
+ * ```
66
+ */
67
+ export declare function Await<T>({ resolve, errorElement, children }: AwaitProps<T>): ReactNode;