@teyik0/furin 0.1.0-alpha.10

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 (87) hide show
  1. package/dist/adapter/bun.d.ts +3 -0
  2. package/dist/adapter/static.d.ts +3 -0
  3. package/dist/build/client.d.ts +25 -0
  4. package/dist/build/compile-entry.d.ts +35 -0
  5. package/dist/build/entry-template.d.ts +26 -0
  6. package/dist/build/hydrate.d.ts +24 -0
  7. package/dist/build/index.d.ts +7 -0
  8. package/dist/build/index.js +4716 -0
  9. package/dist/build/route-types.d.ts +21 -0
  10. package/dist/build/scan-server.d.ts +8 -0
  11. package/dist/build/server-routes-entry.d.ts +35 -0
  12. package/dist/build/shared.d.ts +11 -0
  13. package/dist/build/types.d.ts +76 -0
  14. package/dist/cli/config.d.ts +9 -0
  15. package/dist/cli/index.d.ts +2 -0
  16. package/dist/cli/index.js +4751 -0
  17. package/dist/client.d.ts +195 -0
  18. package/dist/client.js +20 -0
  19. package/dist/config.d.ts +50 -0
  20. package/dist/config.js +28 -0
  21. package/dist/context-logger.d.ts +28 -0
  22. package/dist/dev-page-plugin.d.ts +109 -0
  23. package/dist/error.d.ts +23 -0
  24. package/dist/furin.d.ts +52 -0
  25. package/dist/furin.js +3948 -0
  26. package/dist/internal.d.ts +33 -0
  27. package/dist/link.d.ts +454 -0
  28. package/dist/link.js +1790 -0
  29. package/dist/not-found.d.ts +19 -0
  30. package/dist/plugin/index.d.ts +20 -0
  31. package/dist/plugin/index.js +1408 -0
  32. package/dist/plugin/transform-client.d.ts +9 -0
  33. package/dist/render/assemble.d.ts +15 -0
  34. package/dist/render/boundaries.d.ts +79 -0
  35. package/dist/render/cache.d.ts +96 -0
  36. package/dist/render/default-screens.d.ts +11 -0
  37. package/dist/render/digest.d.ts +16 -0
  38. package/dist/render/element.d.ts +8 -0
  39. package/dist/render/index.d.ts +53 -0
  40. package/dist/render/loaders.d.ts +21 -0
  41. package/dist/render/shell.d.ts +29 -0
  42. package/dist/render/template.d.ts +6 -0
  43. package/dist/router.d.ts +96 -0
  44. package/dist/router.js +2693 -0
  45. package/dist/runtime-env.d.ts +3 -0
  46. package/dist/utils.d.ts +6 -0
  47. package/package.json +77 -0
  48. package/src/adapter/README.md +13 -0
  49. package/src/adapter/bun.ts +239 -0
  50. package/src/adapter/static.ts +341 -0
  51. package/src/build/client.ts +153 -0
  52. package/src/build/compile-entry.ts +129 -0
  53. package/src/build/entry-template.ts +126 -0
  54. package/src/build/hydrate.ts +250 -0
  55. package/src/build/index.ts +151 -0
  56. package/src/build/route-types.ts +89 -0
  57. package/src/build/scan-server.ts +110 -0
  58. package/src/build/server-routes-entry.ts +55 -0
  59. package/src/build/shared.ts +78 -0
  60. package/src/build/types.ts +85 -0
  61. package/src/cli/config.ts +68 -0
  62. package/src/cli/index.ts +115 -0
  63. package/src/client.ts +278 -0
  64. package/src/config.ts +66 -0
  65. package/src/context-logger.ts +74 -0
  66. package/src/dev-page-plugin.ts +434 -0
  67. package/src/env.d.ts +49 -0
  68. package/src/error.ts +32 -0
  69. package/src/furin.ts +383 -0
  70. package/src/internal.ts +51 -0
  71. package/src/link.tsx +1578 -0
  72. package/src/not-found.ts +40 -0
  73. package/src/plugin/index.ts +80 -0
  74. package/src/plugin/transform-client.ts +372 -0
  75. package/src/render/assemble.ts +66 -0
  76. package/src/render/boundaries.tsx +176 -0
  77. package/src/render/cache.ts +251 -0
  78. package/src/render/default-screens.tsx +299 -0
  79. package/src/render/digest.ts +71 -0
  80. package/src/render/element.tsx +119 -0
  81. package/src/render/index.ts +867 -0
  82. package/src/render/loaders.ts +127 -0
  83. package/src/render/shell.ts +187 -0
  84. package/src/render/template.ts +55 -0
  85. package/src/router.ts +779 -0
  86. package/src/runtime-env.ts +6 -0
  87. package/src/utils.ts +68 -0
@@ -0,0 +1,195 @@
1
+ import type { Cookie, StatusMap } from "elysia";
2
+ import type { AnySchema, HTTPHeaders, UnwrapSchema } from "elysia/types";
3
+ import type { RequestLogger } from "evlog";
4
+ declare const UNSET: unique symbol;
5
+ type Unset = typeof UNSET;
6
+ type ToRecord<T> = {
7
+ [K in keyof T]: T[K];
8
+ };
9
+ type ResolvedSchema<T> = [T] extends [Unset] ? Unset : T extends AnySchema ? UnwrapSchema<T> : Unset;
10
+ type MergeSchema<TParent, TOwn> = [TParent] extends [Unset] ? TOwn : [TOwn] extends [Unset] ? TParent : TParent & TOwn;
11
+ type NormalizeUnset<T> = [T] extends [Unset] ? {} : T;
12
+ /**
13
+ * Transforms each key of a parent-data record into an individual `Promise<T>`.
14
+ * This is what child loaders see for inherited fields — direct values from
15
+ * `RouteContext` (request, params, set, …) remain unchanged.
16
+ */
17
+ type PromisifyData<T extends Record<string, unknown>> = {
18
+ [K in keyof T]: Promise<T[K]>;
19
+ };
20
+ export interface RouteContext<TParams = {}, TQuery = {}> {
21
+ cookie: Record<string, Cookie<unknown>>;
22
+ headers: Record<string, string | undefined>;
23
+ /** Request-scoped logger. Call `log.set({})` to attach fields to the wide event for this render. */
24
+ log: RequestLogger;
25
+ params: NormalizeUnset<TParams>;
26
+ path: string;
27
+ query: NormalizeUnset<TQuery>;
28
+ redirect: (url: string, status?: 301 | 302 | 303 | 307 | 308) => Response;
29
+ request: Request;
30
+ set: {
31
+ headers: HTTPHeaders;
32
+ status?: number | keyof StatusMap;
33
+ };
34
+ }
35
+ export interface ComponentProps<TParams = {}, TQuery = {}> {
36
+ params: NormalizeUnset<TParams>;
37
+ path: string;
38
+ query: NormalizeUnset<TQuery>;
39
+ }
40
+ type ResolveParent<T> = T extends RouteRef<infer D, infer P, infer Q> ? {
41
+ data: D;
42
+ params: P;
43
+ query: Q;
44
+ } : {
45
+ data: {};
46
+ params: Unset;
47
+ query: Unset;
48
+ };
49
+ interface Resolved<TParentRef, TLoaderData, TParamsSchema = Unset, TQuerySchema = Unset> {
50
+ data: ToRecord<ResolveParent<TParentRef>["data"] & TLoaderData>;
51
+ params: MergeSchema<ResolveParent<TParentRef>["params"], ResolvedSchema<TParamsSchema>>;
52
+ query: MergeSchema<ResolveParent<TParentRef>["query"], ResolvedSchema<TQuerySchema>>;
53
+ }
54
+ export type MetaDescriptor = {
55
+ charSet: "utf-8";
56
+ } | {
57
+ title: string;
58
+ } | {
59
+ name: string;
60
+ content: string;
61
+ } | {
62
+ property: string;
63
+ content: string;
64
+ } | {
65
+ httpEquiv: string;
66
+ content: string;
67
+ } | {
68
+ "script:ld+json": object;
69
+ } | {
70
+ tagName: "meta" | "link";
71
+ [name: string]: string | undefined;
72
+ };
73
+ export interface HeadOptions {
74
+ links?: Array<{
75
+ rel: string;
76
+ href: string;
77
+ [key: string]: string;
78
+ }>;
79
+ meta?: MetaDescriptor[];
80
+ /**
81
+ * Inline scripts injected into `<head>`.
82
+ *
83
+ * **Security warning:** `children` is injected as raw HTML — never pass
84
+ * user-controlled or loader-derived data here without sanitisation.
85
+ */
86
+ scripts?: Array<{
87
+ src?: string;
88
+ type?: string;
89
+ children?: string;
90
+ [key: string]: string | undefined;
91
+ }>;
92
+ /**
93
+ * Inline styles injected into `<head>`.
94
+ *
95
+ * **Security warning:** `children` is injected as raw HTML — never pass
96
+ * user-controlled or loader-derived data here without sanitisation.
97
+ */
98
+ styles?: Array<{
99
+ type?: string;
100
+ children: string;
101
+ }>;
102
+ }
103
+ type ExtractLoaderReturn<TLoader> = TLoader extends (...args: never[]) => unknown ? Awaited<ReturnType<TLoader>> extends object ? ToRecord<Awaited<ReturnType<TLoader>>> : {} : {};
104
+ export interface PageConfig<TParentData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends object = {}> {
105
+ component: React.FC<TParentData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
106
+ head?: (ctx: ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData) => HeadOptions;
107
+ loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => Promise<TPageLoaderData> | TPageLoaderData;
108
+ staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
109
+ }
110
+ export interface RuntimeRoute {
111
+ __type: "FURIN_ROUTE";
112
+ layout?: React.FC<Record<string, unknown> & {
113
+ children: React.ReactNode;
114
+ }>;
115
+ loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
116
+ mode?: "ssr" | "ssg" | "isr";
117
+ params?: unknown;
118
+ parent?: RuntimeRoute;
119
+ query?: unknown;
120
+ revalidate?: number;
121
+ }
122
+ export interface RuntimePage {
123
+ __type: "FURIN_PAGE";
124
+ _route: RuntimeRoute;
125
+ component: React.FC<Record<string, unknown>>;
126
+ head?(ctx: Record<string, unknown>): HeadOptions;
127
+ loader?(ctx: Record<string, unknown>): Promise<Record<string, unknown>> | Record<string, unknown>;
128
+ staticParams?(): Promise<Record<string, string>[]> | Record<string, string>[];
129
+ }
130
+ export interface RouteRef<TData extends Record<string, unknown> = Record<string, unknown>, TParams = unknown, TQuery = unknown> {
131
+ readonly __brand: "FURIN_ROUTE_REF";
132
+ readonly __phantom: {
133
+ data: TData;
134
+ params: TParams;
135
+ query: TQuery;
136
+ };
137
+ }
138
+ interface PageResult<TData extends Record<string, unknown>, TParams, TQuery, TPageLoaderData extends object> {
139
+ __type: "FURIN_PAGE";
140
+ _route: Route<TData, TParams, TQuery>;
141
+ component: React.FC<TData & TPageLoaderData & ComponentProps<TParams, TQuery>>;
142
+ head?: (ctx: ComponentProps<TParams, TQuery> & TData & TPageLoaderData) => HeadOptions;
143
+ loader?: (ctx: RouteContext<TParams, TQuery> & PromisifyData<TData>) => Promise<TPageLoaderData> | TPageLoaderData;
144
+ }
145
+ export interface Route<TParentData extends Record<string, unknown>, TParams, TQuery> {
146
+ __type: "FURIN_ROUTE";
147
+ layout?: React.FC<TParentData & {
148
+ children: React.ReactNode;
149
+ } & ComponentProps<TParams, TQuery>>;
150
+ loader?(ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>): Promise<TParentData> | TParentData;
151
+ mode?: "ssr" | "ssg" | "isr";
152
+ page<TLoader extends (ctx: RouteContext<TParams, TQuery> & PromisifyData<TParentData>) => unknown, TPageLoaderData extends object = ExtractLoaderReturn<TLoader>>(config: {
153
+ loader: TLoader;
154
+ mode?: "ssr" | "ssg" | "isr";
155
+ revalidate?: number;
156
+ staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
157
+ component: React.FC<NoInfer<TParentData & TPageLoaderData & ComponentProps<TParams, TQuery>>>;
158
+ head?: (ctx: NoInfer<ComponentProps<TParams, TQuery> & TParentData & TPageLoaderData>) => HeadOptions;
159
+ }): PageResult<TParentData, TParams, TQuery, TPageLoaderData>;
160
+ page(config: {
161
+ mode?: "ssr" | "ssg" | "isr";
162
+ revalidate?: number;
163
+ staticParams?: () => Promise<NormalizeUnset<TParams>[]> | NormalizeUnset<TParams>[];
164
+ component: React.FC<TParentData & ComponentProps<TParams, TQuery>>;
165
+ head?: (ctx: ComponentProps<TParams, TQuery> & TParentData) => HeadOptions;
166
+ }): PageResult<TParentData, TParams, TQuery, {}>;
167
+ params?: unknown;
168
+ parent?: RuntimeRoute;
169
+ query?: unknown;
170
+ /** Branded ref for type inference when used as a parent. */
171
+ ref: RouteRef<TParentData, TParams, TQuery>;
172
+ revalidate?: number;
173
+ }
174
+ export declare function createRoute<TParentRef extends RouteRef | undefined = undefined, TParamsSchema extends AnySchema | Unset = Unset, TQuerySchema extends AnySchema | Unset = Unset, TLoaderData extends object = {}>(config?: {
175
+ parent?: {
176
+ ref: TParentRef;
177
+ } & {
178
+ __type: "FURIN_ROUTE";
179
+ };
180
+ mode?: "ssr" | "ssg" | "isr";
181
+ revalidate?: number;
182
+ params?: TParamsSchema;
183
+ query?: TQuerySchema;
184
+ loader?: (ctx: RouteContext<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]> & PromisifyData<ResolveParent<TParentRef>["data"]>) => Promise<TLoaderData> | TLoaderData;
185
+ layout?: React.FC<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["data"] & {
186
+ children: React.ReactNode;
187
+ } & ComponentProps<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]>>;
188
+ }): Route<Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["data"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["params"], Resolved<TParentRef, TLoaderData, TParamsSchema, TQuerySchema>["query"]>;
189
+ export type InferProps<T> = T extends {
190
+ __type: "FURIN_PAGE";
191
+ component: React.FC<infer P>;
192
+ } ? P : T extends Route<infer D, infer P, infer Q> ? D & {
193
+ children: React.ReactNode;
194
+ } & ComponentProps<P, Q> : never;
195
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,20 @@
1
+ // @bun
2
+ // src/client.ts
3
+ function createRoute(config) {
4
+ const route = {
5
+ ...config,
6
+ __type: "FURIN_ROUTE",
7
+ ref: {},
8
+ page(pageConfig) {
9
+ return {
10
+ ...pageConfig,
11
+ __type: "FURIN_PAGE",
12
+ _route: route
13
+ };
14
+ }
15
+ };
16
+ return route;
17
+ }
18
+ export {
19
+ createRoute
20
+ };
@@ -0,0 +1,50 @@
1
+ import type { BunPlugin } from "bun";
2
+ export declare const BUILD_TARGETS: readonly ["bun", "node", "vercel", "cloudflare", "static"];
3
+ export type BuildTarget = (typeof BUILD_TARGETS)[number];
4
+ /**
5
+ * Configuration for the `static` build target.
6
+ * Produces a fully pre-rendered directory deployable to any static host
7
+ * (GitHub Pages, Netlify, Surge.sh, …).
8
+ */
9
+ export interface StaticExportConfig {
10
+ /**
11
+ * Sub-path prefix for GitHub Pages sub-path deployments.
12
+ * e.g. "/furin" when the site is served at `https://user.github.io/furin/`.
13
+ * Must start with "/" and have no trailing slash.
14
+ * Default: "" (site served at root).
15
+ */
16
+ basePath?: string;
17
+ /**
18
+ * Behaviour when SSR or ISR routes are encountered during a static build.
19
+ * - "error" (default): throw at build time with the list of incompatible routes.
20
+ * - "skip": emit a warning and omit those routes from the output.
21
+ */
22
+ onSSR?: "error" | "skip";
23
+ /**
24
+ * Output directory for the static export.
25
+ * Default: "dist".
26
+ */
27
+ outDir?: string;
28
+ }
29
+ export declare const configSchema: import("@sinclair/typebox").TObject<{
30
+ rootDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
31
+ pagesDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
32
+ serverEntry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
33
+ targets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<import("@sinclair/typebox").TLiteral<"bun" | "node" | "vercel" | "cloudflare" | "static">[]>>>;
34
+ bun: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
35
+ compile: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"server">, import("@sinclair/typebox").TLiteral<"embed">]>>;
36
+ }>>;
37
+ static: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
38
+ basePath: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
39
+ outDir: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
40
+ onSSR: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"error">, import("@sinclair/typebox").TLiteral<"skip">]>>;
41
+ }>>;
42
+ }>;
43
+ export type FurinPlugin = BunPlugin & {
44
+ buildOnly?: boolean;
45
+ };
46
+ export type FurinConfig = (typeof configSchema)["static"] & {
47
+ plugins?: FurinPlugin[];
48
+ static?: StaticExportConfig;
49
+ };
50
+ export declare function defineConfig(config: FurinConfig): FurinConfig;
package/dist/config.js ADDED
@@ -0,0 +1,28 @@
1
+ // @bun
2
+ // src/config.ts
3
+ import { t } from "elysia";
4
+ var BUILD_TARGETS = ["bun", "node", "vercel", "cloudflare", "static"];
5
+ var buildTargetSchema = t.Union(BUILD_TARGETS.map((v) => t.Literal(v)));
6
+ var compileTargetSchema = t.Union([t.Literal("server"), t.Literal("embed")]);
7
+ var configSchema = t.Object({
8
+ rootDir: t.Optional(t.String()),
9
+ pagesDir: t.Optional(t.String()),
10
+ serverEntry: t.Optional(t.String()),
11
+ targets: t.Optional(t.Array(buildTargetSchema)),
12
+ bun: t.Optional(t.Object({
13
+ compile: t.Optional(compileTargetSchema)
14
+ })),
15
+ static: t.Optional(t.Object({
16
+ basePath: t.Optional(t.String()),
17
+ outDir: t.Optional(t.String()),
18
+ onSSR: t.Optional(t.Union([t.Literal("error"), t.Literal("skip")]))
19
+ }))
20
+ });
21
+ function defineConfig(config) {
22
+ return config;
23
+ }
24
+ export {
25
+ defineConfig,
26
+ configSchema,
27
+ BUILD_TARGETS
28
+ };
@@ -0,0 +1,28 @@
1
+ import type { RequestLogger } from "evlog";
2
+ import { createLogger } from "evlog";
3
+ export { createLogger };
4
+ /**
5
+ * Returns the current request-scoped logger.
6
+ *
7
+ * Priority:
8
+ * 1. Live Elysia request handled by the evlog() plugin → full request-scoped wide event
9
+ * 2. Synthetic render scope (ISR revalidation, SSG pre-render) → detached createLogger()
10
+ * that still drains to the configured adapter (Datadog, Axiom, etc.)
11
+ * 3. Completely outside any context → no-op
12
+ *
13
+ * Import from `@teyik0/furin` instead of `evlog/elysia` so this fallback chain
14
+ * applies in all rendering contexts.
15
+ */
16
+ export declare function useLogger(): RequestLogger;
17
+ /**
18
+ * Runs `fn` inside a synthetic render scope.
19
+ *
20
+ * Creates a detached `createLogger()` instance for the duration of `fn`.
21
+ * `useLogger()` calls inside `fn` (including user loaders) return this logger
22
+ * instead of throwing. On completion, the accumulated wide event is emitted to
23
+ * the global drain with the provided initial context (e.g. route pattern).
24
+ *
25
+ * Used by renderForPath() which drives both ISR background revalidation and
26
+ * SSG pre-renders — neither has a live Elysia request context.
27
+ */
28
+ export declare function runInSyntheticRenderScope<T>(fn: () => Promise<T> | T, initialContext: Record<string, unknown>): Promise<T>;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Bun.plugin that loads page modules into a virtual namespace so they stay
3
+ * out of `--hot`'s file watcher.
4
+ *
5
+ * `--hot` re-evaluates every real source file in the module graph when any
6
+ * tracked file changes. By resolving page imports to a virtual namespace
7
+ * (`furin-dev-page`), the actual `.tsx` files are never registered as
8
+ * watched sources — edits trigger only the client-side dev bundler (React
9
+ * Fast Refresh) without a full server restart.
10
+ *
11
+ * ## Cache-busting (prevents hydration mismatches)
12
+ *
13
+ * Bun caches every resolved module by its `(namespace, path)` identity.
14
+ * Without cache-busting, the first import of `pages/index.tsx` would be
15
+ * permanently frozen: after a file edit the server would keep returning the
16
+ * stale module while the client received fresh HMR code, causing a React
17
+ * hydration mismatch.
18
+ *
19
+ * Solution: the caller appends `?furin-server&t=<timestamp>` to the import
20
+ * specifier (a new timestamp on every request). `onResolve` preserves the
21
+ * `?t=...` fragment in the resolved path so each request gets a unique
22
+ * `(namespace, path)` key and Bun always calls `onLoad` fresh.
23
+ *
24
+ * ## Relative import rewriting
25
+ *
26
+ * Modules in a virtual namespace cannot resolve relative specifiers on their
27
+ * own (there is no real directory context). We rewrite every `./` / `../`
28
+ * path to an absolute one before returning the source.
29
+ *
30
+ * ## Bare specifier rewriting
31
+ *
32
+ * When `onLoad` returns `loader: "js"`, Bun resolves bare specifiers
33
+ * (e.g. `@teyik0/furin/link`, `shiki`) from the process CWD — not from the
34
+ * page file's directory. On a cold start the CWD and the file's directory
35
+ * often agree, but after `bun --hot` re-evaluates the server the module
36
+ * cache for project-local packages (like `packages/core/src/link.tsx`) may
37
+ * be cleared and re-loaded with a fresh React instance that diverges from the
38
+ * one already cached by `react-dom/server`. The result is the classic
39
+ * "two React copies" crash: `dispatcher.useState === null`.
40
+ *
41
+ * Fix: after transpilation, resolve every bare specifier from the page
42
+ * file's directory via `Bun.resolveSync` and replace it with the
43
+ * canonical on-disk path. This pins each import to exactly the same
44
+ * file-system location that Bun's native module resolver would choose,
45
+ * guaranteeing a single shared React instance regardless of CWD or
46
+ * hot-reload state.
47
+ *
48
+ * All import/re-export occurrences of each quoted specifier are replaced using
49
+ * a context-aware regex (requires a preceding `from` or `import` keyword) so
50
+ * that modules which both import and re-export from the same package are fully
51
+ * rewritten while string literals in non-import positions are left untouched.
52
+ */
53
+ /**
54
+ * Rewrites bare React/react-dom singleton imports in source text to their
55
+ * absolute resolved paths. Handles explicit static import / re-export forms:
56
+ *
57
+ * import { useState } from "react" → import { useState } from "/abs/…"
58
+ * import type { FC } from "react"
59
+ * export { x } from "react"
60
+ * import "react/jsx-dev-runtime"
61
+ *
62
+ * Does NOT touch dynamic `import("react")` or `require("react")`.
63
+ *
64
+ * @internal exported for testing
65
+ */
66
+ export declare function rewriteSingletonImports(source: string): string;
67
+ /**
68
+ * `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
69
+ * mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
70
+ * NOT emit the corresponding import statement — it expects Bun's full bundler
71
+ * pipeline to inject it later.
72
+ *
73
+ * When we return pre-transpiled JS from `onLoad`, that pipeline step never
74
+ * runs, leaving the helpers as undefined free variables. This function scans
75
+ * the transpiled source, detects which mangled helper names are used, and
76
+ * prepends the correct import statements using absolute on-disk paths from
77
+ * `SINGLETON_PATHS`.
78
+ *
79
+ * Helper → package mapping:
80
+ * jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
81
+ * Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
82
+ * jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
83
+ * jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
84
+ *
85
+ * @internal exported for testing
86
+ */
87
+ export declare function injectJsxHelperImports(transpiled: string): string;
88
+ /** @internal exported for testing */
89
+ export declare function rewriteRelativeImports(source: string, dir: string): string;
90
+ /**
91
+ * Rewrites all remaining bare specifiers in the transpiled JS to absolute
92
+ * on-disk paths resolved from `dir` (the page file's directory).
93
+ *
94
+ * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
95
+ * list of *actual* import specifiers (parsing correctly handles template
96
+ * literals, comments, etc.). For each bare specifier that is not already
97
+ * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
98
+ * replaces **every** import/re-export occurrence of the quoted specifier using
99
+ * a context-aware regex with the `g` flag — mirroring the approach used by
100
+ * `rewriteSingletonImports`. This correctly handles modules that both import
101
+ * and re-export from the same package without leaving any bare specifier
102
+ * behind. String literals that happen to contain the same text (inside
103
+ * template literals, JSX props, etc.) are not touched because the regex
104
+ * requires a preceding `from` or `import` keyword.
105
+ *
106
+ * @internal exported for testing
107
+ */
108
+ export declare function rewriteBareImports(source: string, transpiled: string, dir: string): string;
109
+ export declare function registerDevPagePlugin(): void;
@@ -0,0 +1,23 @@
1
+ import type { FC } from "react";
2
+ export interface ErrorProps {
3
+ error: {
4
+ /** Safe user-facing message. */
5
+ message: string;
6
+ /**
7
+ * Opaque 10-hex-char hash of the original error. The same digest appears
8
+ * in the server logs next to the full stack trace, so support can
9
+ * correlate a user-reported error ID with server-side diagnostics
10
+ * without leaking stack traces to the browser.
11
+ */
12
+ digest: string;
13
+ };
14
+ /**
15
+ * Clears the nearest FurinErrorBoundary's error state, remounting its
16
+ * children. On the client this re-runs the route's loader; on the server
17
+ * it's a no-op (the request has already produced output by the time
18
+ * `reset` could run).
19
+ */
20
+ reset: () => void;
21
+ }
22
+ export type ErrorComponent = FC<ErrorProps>;
23
+ export declare function getPublicErrorMessage(error: Error | unknown): string;
@@ -0,0 +1,52 @@
1
+ import { Elysia } from "elysia";
2
+ import { type EvlogElysiaOptions } from "evlog/elysia";
3
+ /**
4
+ * Main Furin plugin.
5
+ *
6
+ * Returns a standalone Elysia instance (async function) so that routes are
7
+ * properly registered in Elysia's router for SPA navigation to work.
8
+ *
9
+ * ## Usage
10
+ *
11
+ * ```ts
12
+ * new Elysia()
13
+ * .use(await furin({ ... }))
14
+ * .listen(3000)
15
+ * ```
16
+ */
17
+ export declare function furin({ pagesDir, logger, }: {
18
+ pagesDir?: string;
19
+ logger?: EvlogElysiaOptions;
20
+ }): Promise<Elysia<"", {
21
+ decorator: {};
22
+ store: {};
23
+ derive: {};
24
+ resolve: {};
25
+ }, {
26
+ typebox: {};
27
+ error: {};
28
+ }, {
29
+ schema: {};
30
+ standaloneSchema: {};
31
+ macro: {};
32
+ macroFn: {};
33
+ parser: {};
34
+ response: {};
35
+ }, {}, {
36
+ derive: {};
37
+ resolve: {};
38
+ schema: {};
39
+ standaloneSchema: {};
40
+ response: {};
41
+ }, {
42
+ derive: {};
43
+ resolve: {};
44
+ schema: {};
45
+ standaloneSchema: {};
46
+ response: {};
47
+ }>>;
48
+ export type { ErrorComponent, ErrorProps } from "./error.ts";
49
+ export type { NotFoundComponent, NotFoundOptions, NotFoundProps, } from "./not-found.ts";
50
+ export { isNotFoundError, notFound } from "./not-found.ts";
51
+ export { revalidatePath, setCachePurger } from "./render/cache.ts";
52
+ export { renderRootNotFound } from "./render/index.ts";