@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.4

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 (134) hide show
  1. package/README.md +4 -0
  2. package/dist/adapter/bun.d.ts +3 -0
  3. package/dist/adapter/static.d.ts +3 -0
  4. package/dist/build/client.d.ts +25 -0
  5. package/dist/build/compile-entry.d.ts +9 -0
  6. package/dist/build/compile-entry.ts +109 -0
  7. package/dist/build/entry-template.d.ts +38 -0
  8. package/dist/build/entry-template.ts +156 -0
  9. package/dist/build/hydrate.d.ts +24 -0
  10. package/dist/build/index.d.ts +8 -0
  11. package/dist/build/index.js +8106 -0
  12. package/dist/build/route-types.d.ts +23 -0
  13. package/dist/build/scan-server.d.ts +8 -0
  14. package/dist/build/server-routes-entry.d.ts +13 -0
  15. package/dist/build/server-routes-entry.ts +36 -0
  16. package/dist/build/shared.d.ts +12 -0
  17. package/dist/build/ssg-cache.d.ts +4 -0
  18. package/dist/build/types.d.ts +80 -0
  19. package/dist/cli/config.d.ts +9 -0
  20. package/dist/cli/index.d.ts +2 -0
  21. package/dist/cli/index.js +8097 -0
  22. package/dist/client/boundaries.d.ts +117 -0
  23. package/dist/client/default-screens.d.ts +17 -0
  24. package/dist/client/link.d.ts +22 -0
  25. package/dist/client/link.js +4391 -0
  26. package/dist/client/router/abort.d.ts +1 -0
  27. package/dist/client/router/boundary-tree.d.ts +26 -0
  28. package/dist/client/router/context.d.ts +8 -0
  29. package/dist/client/router/history.d.ts +9 -0
  30. package/dist/client/router/index.d.ts +11 -0
  31. package/dist/client/router/link-utils.d.ts +53 -0
  32. package/dist/client/router/navigation.d.ts +10 -0
  33. package/dist/client/router/provider.d.ts +4 -0
  34. package/dist/client/router/search/index.d.ts +18 -0
  35. package/dist/client/router/search-store.d.ts +21 -0
  36. package/dist/client/router/spa-response.d.ts +58 -0
  37. package/dist/client/router/sync-catch-up.d.ts +29 -0
  38. package/dist/client/router/types.d.ts +292 -0
  39. package/dist/client/server-error.d.ts +12 -0
  40. package/dist/client/sync.d.ts +25 -0
  41. package/dist/client.d.ts +243 -0
  42. package/dist/client.js +140 -0
  43. package/dist/config.d.ts +57 -0
  44. package/dist/config.js +29 -0
  45. package/dist/env.d.ts +50 -0
  46. package/dist/furin.d.ts +77 -0
  47. package/dist/furin.js +8977 -0
  48. package/dist/plugin/index.d.ts +20 -0
  49. package/dist/plugin/index.js +1500 -0
  50. package/dist/plugin/transform-client.d.ts +10 -0
  51. package/dist/server/auto-invalidate/index.d.ts +4 -0
  52. package/dist/server/auto-invalidate/plugin.d.ts +38 -0
  53. package/dist/server/auto-invalidate/registry.d.ts +9 -0
  54. package/dist/server/auto-invalidate/runtime.d.ts +9 -0
  55. package/dist/server/auto-invalidate/types.d.ts +12 -0
  56. package/dist/server/cache/dev-loader.d.ts +28 -0
  57. package/dist/server/cache/index.d.ts +10 -0
  58. package/dist/server/cache/invalidation.d.ts +12 -0
  59. package/dist/server/cache/isr-ssg.d.ts +26 -0
  60. package/dist/server/cache/isr.d.ts +6 -0
  61. package/dist/server/cache/registry.d.ts +5 -0
  62. package/dist/server/cache/route-cache.d.ts +26 -0
  63. package/dist/server/cache/ssg.d.ts +5 -0
  64. package/dist/server/context-logger.d.ts +28 -0
  65. package/dist/server/dev-inspector.d.ts +89 -0
  66. package/dist/server/dev-page-plugin.d.ts +112 -0
  67. package/dist/server/internal.d.ts +35 -0
  68. package/dist/server/internal.js +17 -0
  69. package/dist/server/lang-detect.d.ts +5 -0
  70. package/dist/server/render/assemble.d.ts +49 -0
  71. package/dist/server/render/element.d.ts +24 -0
  72. package/dist/server/render/index.d.ts +7 -0
  73. package/dist/server/render/index.ts +22 -0
  74. package/dist/server/render/isr.d.ts +4 -0
  75. package/dist/server/render/loaders.d.ts +64 -0
  76. package/dist/server/render/not-found.d.ts +6 -0
  77. package/dist/server/render/shell.d.ts +39 -0
  78. package/dist/server/render/shell.ts +202 -0
  79. package/dist/server/render/ssg.d.ts +9 -0
  80. package/dist/server/render/ssr.d.ts +108 -0
  81. package/dist/server/render/template.d.ts +6 -0
  82. package/dist/server/router/discovery.d.ts +16 -0
  83. package/dist/server/router/hmr.d.ts +65 -0
  84. package/dist/server/router/index.d.ts +6 -0
  85. package/dist/server/router/index.js +27 -0
  86. package/dist/server/router/index.ts +28 -0
  87. package/dist/server/router/patterns.d.ts +40 -0
  88. package/dist/server/router/plugin.d.ts +21 -0
  89. package/dist/server/router/schemas.d.ts +59 -0
  90. package/dist/server/router/types.d.ts +60 -0
  91. package/dist/server/runtime-env.d.ts +3 -0
  92. package/dist/server/runtime-env.js +10 -0
  93. package/dist/server/sync/adapter.d.ts +62 -0
  94. package/dist/server/sync/config.d.ts +6 -0
  95. package/dist/server/sync/fingerprint.d.ts +6 -0
  96. package/dist/server/sync/index.d.ts +4 -0
  97. package/dist/server/sync/memory-adapter.d.ts +17 -0
  98. package/dist/server/sync/plugin.d.ts +186 -0
  99. package/dist/server/sync/response.d.ts +4 -0
  100. package/dist/server/sync/stream.d.ts +59 -0
  101. package/dist/shared/await.d.ts +67 -0
  102. package/dist/shared/deferred-ndjson.d.ts +32 -0
  103. package/dist/shared/digest.d.ts +16 -0
  104. package/dist/shared/error.d.ts +37 -0
  105. package/dist/shared/not-found.d.ts +19 -0
  106. package/dist/shared/search-params.d.ts +17 -0
  107. package/dist/shared/utils/ast-walk.d.ts +18 -0
  108. package/dist/shared/utils/index.d.ts +13 -0
  109. package/package.json +5 -5
  110. package/src/build/hydrate.ts +4 -1
  111. package/src/build/shared.ts +4 -3
  112. package/src/client/router/abort.ts +5 -0
  113. package/src/client/router/link-utils.ts +8 -1
  114. package/src/client/router/provider.tsx +130 -6
  115. package/src/client/router/sync-catch-up.ts +113 -0
  116. package/src/client/router/types.ts +5 -0
  117. package/src/client/sync.ts +98 -0
  118. package/src/client.ts +15 -1
  119. package/src/furin.ts +25 -4
  120. package/src/server/auto-invalidate/runtime.ts +3 -2
  121. package/src/server/dev-page-plugin.ts +15 -10
  122. package/src/server/render/assemble.ts +30 -3
  123. package/src/server/render/isr.ts +8 -2
  124. package/src/server/render/ssr.ts +9 -1
  125. package/src/server/router/plugin.ts +2 -2
  126. package/src/server/sync/adapter.ts +65 -0
  127. package/src/server/sync/config.ts +29 -0
  128. package/src/server/sync/fingerprint.ts +44 -0
  129. package/src/server/sync/index.ts +15 -0
  130. package/src/server/sync/memory-adapter.ts +196 -0
  131. package/src/server/sync/plugin.ts +200 -0
  132. package/src/server/sync/response.ts +77 -0
  133. package/src/server/sync/stream.ts +152 -0
  134. package/src/shared/deferred-ndjson.ts +7 -0
@@ -0,0 +1,10 @@
1
+ import MagicString from "magic-string";
2
+ import { type SourceLang } from "yuku-parser";
3
+ interface TransformResult {
4
+ code: string;
5
+ map: ReturnType<MagicString["generateMap"]> | null;
6
+ removedServerCode: boolean;
7
+ }
8
+ export declare function deadCodeElimination(s: MagicString, lang: SourceLang): MagicString;
9
+ export declare function transformForClient(code: string, filename: string): TransformResult;
10
+ export {};
@@ -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"]): string[];
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 "../cache/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,28 @@
1
+ import { type RevalidateType } from "./route-cache";
2
+ export interface DevLoaderCacheEntry {
3
+ dependencies: string[];
4
+ generatedAt: number;
5
+ headers: Record<string, string>;
6
+ loaderData: Record<string, unknown>;
7
+ mode: "isr" | "ssg";
8
+ revalidate: number;
9
+ }
10
+ export interface InvalidateOutcome {
11
+ cleared: string[];
12
+ isr: number;
13
+ ssg: number;
14
+ }
15
+ export declare const devISRLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
16
+ export declare const devSSGLoaderCache: import("./route-cache").Cache<DevLoaderCacheEntry>;
17
+ export declare function getDevISRLoaderCache(key: string): DevLoaderCacheEntry | undefined;
18
+ export declare function setDevISRLoaderCache(key: string, entry: DevLoaderCacheEntry): void;
19
+ export declare function getDevSSGLoaderCache(key: string): DevLoaderCacheEntry | undefined;
20
+ export declare function setDevSSGLoaderCache(key: string, entry: DevLoaderCacheEntry): void;
21
+ export declare function urlPathFromCacheKey(key: string): string | null;
22
+ export declare function invalidateDevLoaderCacheByPath(path: string, type: RevalidateType): InvalidateOutcome;
23
+ export declare function invalidateDevLoaderCacheBySource(filePath: string): InvalidateOutcome;
24
+ export declare function isDevLoaderCacheFresh(entry: DevLoaderCacheEntry): boolean;
25
+ export declare function isDevLoaderCacheValid(entry: DevLoaderCacheEntry): boolean;
26
+ export declare function getAllDevISRLoaderEntries(): [string, DevLoaderCacheEntry][];
27
+ export declare function getAllDevSSGLoaderEntries(): [string, DevLoaderCacheEntry][];
28
+ export declare function __resetDevLoaderCacheState(): void;
@@ -0,0 +1,10 @@
1
+ export type { DevLoaderCacheEntry, InvalidateOutcome } from "./dev-loader";
2
+ export { __resetDevLoaderCacheState, getAllDevISRLoaderEntries, getAllDevSSGLoaderEntries, getDevISRLoaderCache, getDevSSGLoaderCache, invalidateDevLoaderCacheByPath, invalidateDevLoaderCacheBySource, isDevLoaderCacheFresh, isDevLoaderCacheValid, setDevISRLoaderCache, setDevSSGLoaderCache, urlPathFromCacheKey, } from "./dev-loader";
3
+ export { __resetCacheState, _runWithRequestInvalidationScope, callCachePurger, consumePendingInvalidations, getBuildId, revalidatePath, setBuildId, setCachePurger, } from "./invalidation";
4
+ export { deleteISRCache, getISRCache, isrCache, setISRCache } from "./isr";
5
+ export type { ISRCacheEntry, SsgCacheEntry } from "./isr-ssg";
6
+ export type { CacheInvalidator } from "./registry";
7
+ export { registerCacheInvalidator } from "./registry";
8
+ export type { Cache, CacheInvalidationResult, RevalidateType } from "./route-cache";
9
+ export { createRouteCache } from "./route-cache";
10
+ export { getSSGCache, setSSGCache, ssgCache } from "./ssg";
@@ -0,0 +1,12 @@
1
+ import type { RevalidateType } from "./route-cache";
2
+ export declare function setBuildId(id: string): void;
3
+ export declare function getBuildId(): string;
4
+ export declare function _runWithRequestInvalidationScope<T>(fn: () => T): T;
5
+ export declare function consumePendingInvalidations(): string[];
6
+ type CachePurger = (paths: string[]) => Promise<void>;
7
+ export declare function setCachePurger(fn: CachePurger): void;
8
+ export declare function callCachePurger(paths: string[]): void;
9
+ export declare function revalidatePath(path: string, type: RevalidateType): boolean;
10
+ /** @internal — resets all module state between tests */
11
+ export declare function __resetCacheState(): void;
12
+ export {};
@@ -0,0 +1,26 @@
1
+ import { type Cache } from "./route-cache";
2
+ export interface ISRCacheEntry {
3
+ generatedAt: number;
4
+ html: string;
5
+ revalidate: number;
6
+ }
7
+ export interface SsgCacheEntry {
8
+ cachedAt: number;
9
+ html: string;
10
+ /**
11
+ * NDJSON payload identical in shape to what the live `/_furin/data` endpoint
12
+ * emits. Persisted alongside the HTML by the static adapter so SPA navigation
13
+ * on a static-hosted deployment can fetch loader data without going through
14
+ * a runtime endpoint that does not exist on a file server.
15
+ */
16
+ ndjson: string;
17
+ status: number;
18
+ tags?: string[];
19
+ }
20
+ /**
21
+ * Builds the LRU cache backing one render mode's pre-rendered HTML. ISR and SSG
22
+ * share the same eviction bound and the same `onDelete` hook — which keeps the
23
+ * auto-invalidate path registry in sync — and differ only in entry shape and
24
+ * the diagnostic `name`.
25
+ */
26
+ export declare function createHtmlRouteCache<Entry>(mode: "isr" | "ssg"): Cache<Entry>;
@@ -0,0 +1,6 @@
1
+ import { type ISRCacheEntry } from "./isr-ssg";
2
+ export declare const isrRouteCache: import("./route-cache").Cache<ISRCacheEntry>;
3
+ export declare const isrCache: Map<string, ISRCacheEntry>;
4
+ export declare function getISRCache(key: string): ISRCacheEntry | undefined;
5
+ export declare function deleteISRCache(key: string): boolean;
6
+ export declare function setISRCache(key: string, entry: ISRCacheEntry): void;
@@ -0,0 +1,5 @@
1
+ import type { Cache } from "./route-cache";
2
+ export type CacheInvalidator = Pick<Cache<unknown>, "invalidatePath" | "name">;
3
+ export declare function registerCacheInvalidator(invalidator: CacheInvalidator): () => void;
4
+ export declare function getCacheInvalidators(): IterableIterator<CacheInvalidator>;
5
+ export declare function clearCacheInvalidators(): void;
@@ -0,0 +1,26 @@
1
+ export type RevalidateType = "page" | "layout";
2
+ export interface CacheInvalidationResult {
3
+ deleted: boolean;
4
+ purgedPaths: string[];
5
+ }
6
+ export interface Cache<Entry> {
7
+ clear(): void;
8
+ delete(key: string): boolean;
9
+ entries(): IterableIterator<[string, Entry]>;
10
+ get(key: string): Entry | undefined;
11
+ has(key: string): boolean;
12
+ invalidatePath(path: string, type: RevalidateType): CacheInvalidationResult;
13
+ keys(): IterableIterator<string>;
14
+ readonly name: string;
15
+ set(key: string, entry: Entry): void;
16
+ get size(): number;
17
+ readonly store: Map<string, Entry>;
18
+ }
19
+ export interface RouteCacheOptions<Entry> {
20
+ maxSize?: number;
21
+ name: string;
22
+ onDelete?: (key: string, entry: Entry) => void;
23
+ onSet?: (key: string, entry: Entry, previous: Entry | undefined) => void;
24
+ pathFromKey?: (key: string) => string | null;
25
+ }
26
+ export declare function createRouteCache<Entry>(options: RouteCacheOptions<Entry>): Cache<Entry>;
@@ -0,0 +1,5 @@
1
+ import { type SsgCacheEntry } from "./isr-ssg";
2
+ export declare const ssgRouteCache: import("./route-cache").Cache<SsgCacheEntry>;
3
+ export declare const ssgCache: Map<string, SsgCacheEntry>;
4
+ export declare function getSSGCache(key: string): SsgCacheEntry | undefined;
5
+ export declare function setSSGCache(key: string, entry: SsgCacheEntry): void;
@@ -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,89 @@
1
+ import { Elysia } from "elysia";
2
+ /**
3
+ * Dev "Live ISR" inspector.
4
+ *
5
+ * Mounts read-only JSON endpoints that surface the active entries of the
6
+ * dev-mode loader caches. Designed to back a future browser DevTools panel:
7
+ * the JSON shape is stable and carries enough information for a UI to render
8
+ * a freshness-aware entry list with dependencies and a data preview.
9
+ *
10
+ * The plugin always registers the routes — caller is responsible for gating
11
+ * on `IS_DEV` to keep them out of production builds.
12
+ */
13
+ /** Public response shape — keep stable for downstream UI consumers. */
14
+ export interface InspectorEntry {
15
+ /** Per-entry preview of the cached loader output. */
16
+ dataPreview: Record<string, unknown>;
17
+ /** Source files whose change drops this entry. */
18
+ dependencies: string[];
19
+ /** ms timestamp at which the entry was written. */
20
+ generatedAt: number;
21
+ /** True iff the entry is still within its `revalidate` window. */
22
+ isFresh: boolean;
23
+ /** Resolved cache key (the same path used by `revalidatePath`). */
24
+ key: string;
25
+ /** Cache origin — surfaced verbatim so a UI can group by mode. */
26
+ mode: "isr" | "ssg";
27
+ /** Revalidate window in seconds. SSG entries report `-1` for "indefinite". */
28
+ revalidate: number;
29
+ }
30
+ export declare function createDevInspectorPlugin(): Elysia<"", {
31
+ decorator: {};
32
+ store: {};
33
+ derive: {};
34
+ resolve: {};
35
+ }, {
36
+ typebox: {};
37
+ error: {};
38
+ }, {
39
+ schema: {};
40
+ standaloneSchema: {};
41
+ macro: {};
42
+ macroFn: {};
43
+ parser: {};
44
+ response: {};
45
+ }, {
46
+ __furin: {
47
+ _inspect: {
48
+ isr: {
49
+ get: {
50
+ body: unknown;
51
+ params: {};
52
+ query: unknown;
53
+ headers: unknown;
54
+ response: {
55
+ 200: InspectorEntry[];
56
+ };
57
+ };
58
+ };
59
+ };
60
+ };
61
+ } & {
62
+ __furin: {
63
+ _inspect: {
64
+ ssg: {
65
+ get: {
66
+ body: unknown;
67
+ params: {};
68
+ query: unknown;
69
+ headers: unknown;
70
+ response: {
71
+ 200: InspectorEntry[];
72
+ };
73
+ };
74
+ };
75
+ };
76
+ };
77
+ }, {
78
+ derive: {};
79
+ resolve: {};
80
+ schema: {};
81
+ standaloneSchema: {};
82
+ response: {};
83
+ }, {
84
+ derive: {};
85
+ resolve: {};
86
+ schema: {};
87
+ standaloneSchema: {};
88
+ response: {};
89
+ }>;
@@ -0,0 +1,112 @@
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
+ export declare const WORKSPACE_SOURCE_FILTER: RegExp;
54
+ /** Converts a native absolute path to Bun's cross-platform import format. */
55
+ export declare function toImportSpecifier(filePath: string): string;
56
+ /**
57
+ * Rewrites bare React/react-dom singleton imports in source text to their
58
+ * absolute resolved paths. Handles explicit static import / re-export forms:
59
+ *
60
+ * import { useState } from "react" → import { useState } from "/abs/…"
61
+ * import type { FC } from "react"
62
+ * export { x } from "react"
63
+ * import "react/jsx-dev-runtime"
64
+ *
65
+ * Does NOT touch dynamic `import("react")` or `require("react")`.
66
+ *
67
+ * @internal exported for testing
68
+ */
69
+ export declare function rewriteSingletonImports(source: string): string;
70
+ /**
71
+ * `Bun.Transpiler.transformSync` converts JSX syntax to function calls using
72
+ * mangled helper names (e.g. `jsxDEV_7x81h0kn`, `Fragment_8vg9x3sq`) but does
73
+ * NOT emit the corresponding import statement — it expects Bun's full bundler
74
+ * pipeline to inject it later.
75
+ *
76
+ * When we return pre-transpiled JS from `onLoad`, that pipeline step never
77
+ * runs, leaving the helpers as undefined free variables. This function scans
78
+ * the transpiled source, detects which mangled helper names are used, and
79
+ * prepends the correct import statements using absolute on-disk paths from
80
+ * `SINGLETON_PATHS`.
81
+ *
82
+ * Helper → package mapping:
83
+ * jsxDEV_* → `{ jsxDEV as … }` from react/jsx-dev-runtime
84
+ * Fragment_* → `{ Fragment as … }` from react/jsx-dev-runtime
85
+ * jsx_* → `{ jsx as … }` from react/jsx-runtime (prod only)
86
+ * jsxs_* → `{ jsxs as … }` from react/jsx-runtime (prod only)
87
+ *
88
+ * @internal exported for testing
89
+ */
90
+ export declare function injectJsxHelperImports(transpiled: string): string;
91
+ /** @internal exported for testing */
92
+ export declare function rewriteRelativeImports(source: string, dir: string): string;
93
+ /**
94
+ * Rewrites all remaining bare specifiers in the transpiled JS to absolute
95
+ * on-disk paths resolved from `dir` (the page file's directory).
96
+ *
97
+ * Uses `Bun.Transpiler.scan()` on the original source to get the authoritative
98
+ * list of *actual* import specifiers (parsing correctly handles template
99
+ * literals, comments, etc.). For each bare specifier that is not already
100
+ * handled by `rewriteSingletonImports`, it calls `Bun.resolveSync` and
101
+ * replaces **every** import/re-export occurrence of the quoted specifier using
102
+ * a context-aware regex with the `g` flag — mirroring the approach used by
103
+ * `rewriteSingletonImports`. This correctly handles modules that both import
104
+ * and re-export from the same package without leaving any bare specifier
105
+ * behind. String literals that happen to contain the same text (inside
106
+ * template literals, JSX props, etc.) are not touched because the regex
107
+ * requires a preceding `from` or `import` keyword.
108
+ *
109
+ * @internal exported for testing
110
+ */
111
+ export declare function rewriteBareImports(source: string, transpiled: string, dir: string): string;
112
+ export declare function registerDevPagePlugin(): void;
@@ -0,0 +1,35 @@
1
+ import type { SsgCacheEntry } from "./cache/index.ts";
2
+ export interface EmbeddedAppData {
3
+ assets: Record<string, string>;
4
+ template: string;
5
+ }
6
+ export interface CompileContextRoute {
7
+ mode: "ssr" | "ssg" | "isr";
8
+ path: string;
9
+ pattern: string;
10
+ }
11
+ export interface CompileContext {
12
+ buildId?: string;
13
+ embedded?: EmbeddedAppData;
14
+ modules: Record<string, unknown>;
15
+ /** Root-level conventions discovered at compile time. */
16
+ rootConventions?: {
17
+ errorPath?: string;
18
+ notFoundPath?: string;
19
+ };
20
+ rootPath: string;
21
+ /** Per-route metadata including pre-computed segment boundaries. */
22
+ routeMetadata?: Record<string, {
23
+ segmentBoundaries: Array<{
24
+ depth: number;
25
+ path: string;
26
+ errorPath?: string;
27
+ notFoundPath?: string;
28
+ }>;
29
+ }>;
30
+ routes: CompileContextRoute[];
31
+ ssgCache?: Record<string, SsgCacheEntry>;
32
+ }
33
+ export declare function __setCompileContext(ctx: CompileContext): void;
34
+ export declare function getCompileContext(): CompileContext | null;
35
+ export declare function __resetCompileContext(): void;
@@ -0,0 +1,17 @@
1
+ // @bun
2
+ // src/server/internal.ts
3
+ var _compileCtx = null;
4
+ function __setCompileContext(ctx) {
5
+ _compileCtx = ctx;
6
+ }
7
+ function getCompileContext() {
8
+ return _compileCtx;
9
+ }
10
+ function __resetCompileContext() {
11
+ _compileCtx = null;
12
+ }
13
+ export {
14
+ getCompileContext,
15
+ __setCompileContext,
16
+ __resetCompileContext
17
+ };
@@ -0,0 +1,5 @@
1
+ import type { SourceLang } from "yuku-parser";
2
+ export declare function detectLangFromPath(filePath: string): SourceLang;
3
+ export declare function unwrapTSExpression<T extends {
4
+ type: string;
5
+ }>(node: T): T;
@@ -0,0 +1,49 @@
1
+ import type { toCrossJSON } from "seroval";
2
+ import type { buildHeadInjection } from "./shell";
3
+ /**
4
+ * Single source of truth for the global registry name used by the SSR
5
+ * streaming script, the client hydration entry, and any test helper. Keeping
6
+ * it centralised here avoids `<script>`/JS source drift if the name is ever
7
+ * renamed.
8
+ */
9
+ export declare const FURIN_DEFERRED_GLOBAL = "__FURIN_DEFERRED__";
10
+ /**
11
+ * Generates the `window.__FURIN_DEFERRED__` registry script that is injected
12
+ * BEFORE the React stream starts. It sets up the resolve/reject/getPromise API
13
+ * for late chunks.
14
+ *
15
+ * Client-side `<Await>` components call `getPromise(key)` to obtain a Promise
16
+ * they can pass to React 19's `use()`. The late resolution scripts call
17
+ * `resolve(key, chunk)` / `reject(key, chunk)` to settle those Promises.
18
+ *
19
+ * Synchronous loader data is NOT carried here — it lives exclusively in the
20
+ * `__FURIN_DATA__` JSON script that the hydrate entry reads.
21
+ *
22
+ * CSP note: this is an inline `<script>` — nonce support is a v2 concern.
23
+ */
24
+ export declare function buildDeferredScript(deferredKeys: string[]): string;
25
+ /**
26
+ * Generates a late `<script>` that settles one deferred Promise on the client.
27
+ * The `chunk` must be a seroval CrossJSON value produced by `toCrossJSON(value)`.
28
+ *
29
+ * @param key - The Promise key (matches what `getPromise(key)` was called with)
30
+ * @param chunk - The already-serialised CrossJSON value
31
+ * @param action - "resolve" or "reject"
32
+ */
33
+ export declare function buildDeferredResolution(key: string, chunk: ReturnType<typeof toCrossJSON>, action: "resolve" | "reject"): string;
34
+ /** Minimal context passed to background / synthetic render helpers — only `request` is needed. */
35
+ export interface LoaderContext {
36
+ request: Request;
37
+ }
38
+ export declare function resolvePath(pattern: string, params: Record<string, string>): string;
39
+ export declare function streamToString(stream: ReadableStream): Promise<string>;
40
+ interface SplitTemplate {
41
+ bodyPost: string;
42
+ bodyPre: string;
43
+ headPre: string;
44
+ }
45
+ export declare function splitTemplate(template: string): SplitTemplate;
46
+ export declare function assembleHTML(template: string, headData: ReturnType<typeof buildHeadInjection>, reactHtml: string, data: Record<string, unknown> | undefined): string;
47
+ export declare function buildSyncRuntimeScript(): string;
48
+ export declare function injectSyncRuntimeScript(html: string): string;
49
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from "react";
2
+ import type { RuntimeRoute } from "../../client.ts";
3
+ import type { ErrorComponent } from "../../shared/error.ts";
4
+ import type { FurinNotFoundError, NotFoundComponent } from "../../shared/not-found.ts";
5
+ import type { ResolvedRoute } from "../router/index.ts";
6
+ export declare function buildElement(route: ResolvedRoute, data: Record<string, unknown>, rootLayout: RuntimeRoute): ReactNode;
7
+ export declare function buildNotFoundElement(component: NotFoundComponent | undefined, error: FurinNotFoundError): ReactNode;
8
+ /**
9
+ * Builds the error element rendered when a loader (or the SSR shell) fails.
10
+ *
11
+ * @param component - User-declared `error.tsx` component, or `undefined` to
12
+ * fall back to the built-in `DefaultErrorScreen` with a generic message.
13
+ * @param error - The original thrown value. Kept for `errorMessageOf` lookup
14
+ * when no explicit `messageOverride` is provided (e.g. shell-render errors).
15
+ * @param digest - 10-hex-char digest correlating with server logs.
16
+ * @param messageOverride - Pre-extracted public message. Set by the loader
17
+ * pipeline when the thrown value is a `Response` (whose body has already
18
+ * been consumed in `runLoaders`); pass `undefined` to derive the message
19
+ * from `error` via `errorMessageOf`.
20
+ * @param status - HTTP status to surface in `ErrorProps.error.status`. The
21
+ * loader pipeline passes the thrown `Response.status` (default 500); the
22
+ * shell-error recovery path always passes 500.
23
+ */
24
+ export declare function buildErrorElement(component: ErrorComponent | undefined, error: unknown, digest: string, messageOverride: string | undefined, status: number): ReactNode;
@@ -0,0 +1,7 @@
1
+ export { type LoaderContext, streamToString } from "./assemble.ts";
2
+ export { buildElement, buildErrorElement } from "./element.tsx";
3
+ export { handleISR } from "./isr.ts";
4
+ export { type LoaderResult, runLoaders, serializeDeferredRejection } from "./loaders.ts";
5
+ export { renderRootNotFound } from "./not-found.ts";
6
+ export { prerenderSSG, warmSSGCache } from "./ssg.ts";
7
+ export { assertDeferredModeAllowed, type PreparedRender, prepareRender, type RenderResult, renderForPath, renderSSR, renderToHTML, renderToStream, serializeLoaderDataNdjson, splitBeforeBodyClose, withSSRRouterContext, } from "./ssr.ts";
@@ -0,0 +1,22 @@
1
+ // biome-ignore-all lint/performance/noBarrelFile: intentional barrel for public API
2
+
3
+ export { type LoaderContext, streamToString } from "./assemble.ts";
4
+ export { buildElement, buildErrorElement } from "./element.tsx";
5
+ export { handleISR } from "./isr.ts";
6
+ export { type LoaderResult, runLoaders, serializeDeferredRejection } from "./loaders.ts";
7
+ export { renderRootNotFound } from "./not-found.ts";
8
+
9
+ export { prerenderSSG, warmSSGCache } from "./ssg.ts";
10
+ export {
11
+ assertDeferredModeAllowed,
12
+ type PreparedRender,
13
+ prepareRender,
14
+ type RenderResult,
15
+ renderForPath,
16
+ renderSSR,
17
+ renderToHTML,
18
+ renderToStream,
19
+ serializeLoaderDataNdjson,
20
+ splitBeforeBodyClose,
21
+ withSSRRouterContext,
22
+ } from "./ssr.ts";
@@ -0,0 +1,4 @@
1
+ import type { Context } from "elysia";
2
+ import type { SearchRouteMetadata } from "../../shared/search-params.ts";
3
+ import type { ResolvedRoute, RootLayout } from "../router/index.ts";
4
+ export declare function handleISR(route: ResolvedRoute, ctx: Context, root: RootLayout, buildId: string | undefined, searchRoutes?: SearchRouteMetadata[]): Promise<string | Response | undefined>;