@teyik0/furin 0.1.0-alpha.9 → 0.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/package.json +61 -25
  4. package/src/adapter/bun.ts +90 -41
  5. package/src/adapter/static.ts +100 -40
  6. package/src/build/client.ts +13 -14
  7. package/src/build/compile-entry.ts +20 -14
  8. package/src/build/entry-template.ts +90 -8
  9. package/src/build/hydrate.ts +219 -36
  10. package/src/build/index.ts +10 -9
  11. package/src/build/route-types.ts +65 -9
  12. package/src/build/scan-server.ts +52 -67
  13. package/src/build/server-routes-entry.ts +7 -11
  14. package/src/build/shared.ts +2 -1
  15. package/src/build/ssg-cache.ts +32 -0
  16. package/src/build/types.ts +5 -1
  17. package/src/cli/index.ts +1 -0
  18. package/src/client/boundaries.tsx +259 -0
  19. package/src/client/default-screens.tsx +304 -0
  20. package/src/client/link.tsx +347 -0
  21. package/src/client/router/boundary-tree.tsx +116 -0
  22. package/src/client/router/context.ts +40 -0
  23. package/src/client/router/history.ts +41 -0
  24. package/src/client/router/index.ts +56 -0
  25. package/src/client/router/link-utils.ts +177 -0
  26. package/src/client/router/navigation.ts +61 -0
  27. package/src/client/router/provider.tsx +759 -0
  28. package/src/client/router/search/index.ts +99 -0
  29. package/src/client/router/search-store.ts +86 -0
  30. package/src/client/router/spa-response.ts +143 -0
  31. package/src/client/router/types.ts +271 -0
  32. package/src/client/server-error.ts +47 -0
  33. package/src/client.ts +80 -3
  34. package/src/config.ts +11 -3
  35. package/src/env.d.ts +1 -0
  36. package/src/furin.ts +114 -29
  37. package/src/plugin/index.ts +7 -8
  38. package/src/plugin/transform-client.ts +146 -120
  39. package/src/server/auto-invalidate/index.ts +10 -0
  40. package/src/server/auto-invalidate/plugin.ts +25 -0
  41. package/src/server/auto-invalidate/registry.ts +60 -0
  42. package/src/server/auto-invalidate/runtime.ts +133 -0
  43. package/src/server/auto-invalidate/types.ts +16 -0
  44. package/src/server/cache/dev-loader.ts +211 -0
  45. package/src/server/cache/index.ts +34 -0
  46. package/src/server/cache/invalidation.ts +111 -0
  47. package/src/server/cache/isr-ssg.ts +41 -0
  48. package/src/server/cache/isr.ts +17 -0
  49. package/src/server/cache/registry.ts +35 -0
  50. package/src/server/cache/route-cache.ts +124 -0
  51. package/src/server/cache/ssg.ts +15 -0
  52. package/src/{context-logger.ts → server/context-logger.ts} +5 -0
  53. package/src/server/dev-inspector.ts +60 -0
  54. package/src/{dev-page-plugin.ts → server/dev-page-plugin.ts} +15 -0
  55. package/src/{internal.ts → server/internal.ts} +17 -0
  56. package/src/server/lang-detect.ts +46 -0
  57. package/src/server/render/assemble.ts +133 -0
  58. package/src/server/render/element.tsx +113 -0
  59. package/src/server/render/index.ts +22 -0
  60. package/src/server/render/isr.ts +317 -0
  61. package/src/server/render/loaders.ts +328 -0
  62. package/src/server/render/not-found.ts +98 -0
  63. package/src/{render → server/render}/shell.ts +28 -13
  64. package/src/server/render/ssg.ts +148 -0
  65. package/src/server/render/ssr.ts +583 -0
  66. package/src/server/router/discovery.ts +474 -0
  67. package/src/server/router/hmr.ts +376 -0
  68. package/src/server/router/index.ts +28 -0
  69. package/src/server/router/patterns.ts +219 -0
  70. package/src/server/router/plugin.ts +384 -0
  71. package/src/server/router/schemas.ts +278 -0
  72. package/src/server/router/types.ts +59 -0
  73. package/src/shared/await.tsx +192 -0
  74. package/src/shared/deferred-ndjson.ts +244 -0
  75. package/src/shared/digest.ts +71 -0
  76. package/src/shared/error.ts +49 -0
  77. package/src/shared/not-found.ts +40 -0
  78. package/src/shared/search-params.ts +182 -0
  79. package/src/shared/utils/ast-walk.ts +51 -0
  80. package/src/{utils.ts → shared/utils/index.ts} +32 -1
  81. package/dist/adapter/bun.d.ts +0 -3
  82. package/dist/adapter/static.d.ts +0 -3
  83. package/dist/build/client.d.ts +0 -25
  84. package/dist/build/compile-entry.d.ts +0 -23
  85. package/dist/build/entry-template.d.ts +0 -14
  86. package/dist/build/hydrate.d.ts +0 -24
  87. package/dist/build/index.d.ts +0 -7
  88. package/dist/build/index.js +0 -3727
  89. package/dist/build/route-types.d.ts +0 -21
  90. package/dist/build/scan-server.d.ts +0 -8
  91. package/dist/build/server-routes-entry.d.ts +0 -23
  92. package/dist/build/shared.d.ts +0 -11
  93. package/dist/build/types.d.ts +0 -76
  94. package/dist/cli/config.d.ts +0 -9
  95. package/dist/cli/index.d.ts +0 -2
  96. package/dist/cli/index.js +0 -3762
  97. package/dist/client.d.ts +0 -195
  98. package/dist/client.js +0 -20
  99. package/dist/config.d.ts +0 -47
  100. package/dist/config.js +0 -28
  101. package/dist/context-logger.d.ts +0 -26
  102. package/dist/dev-page-plugin.d.ts +0 -109
  103. package/dist/furin.d.ts +0 -34
  104. package/dist/furin.js +0 -2744
  105. package/dist/internal.d.ts +0 -19
  106. package/dist/link.d.ts +0 -245
  107. package/dist/link.js +0 -1232
  108. package/dist/plugin/index.d.ts +0 -20
  109. package/dist/plugin/index.js +0 -1408
  110. package/dist/plugin/transform-client.d.ts +0 -9
  111. package/dist/render/assemble.d.ts +0 -15
  112. package/dist/render/cache.d.ts +0 -95
  113. package/dist/render/element.d.ts +0 -4
  114. package/dist/render/index.d.ts +0 -27
  115. package/dist/render/loaders.d.ts +0 -12
  116. package/dist/render/shell.d.ts +0 -29
  117. package/dist/render/template.d.ts +0 -6
  118. package/dist/router.d.ts +0 -45
  119. package/dist/router.js +0 -1671
  120. package/dist/runtime-env.d.ts +0 -3
  121. package/dist/utils.d.ts +0 -6
  122. package/src/link.tsx +0 -1120
  123. package/src/render/assemble.ts +0 -66
  124. package/src/render/cache.ts +0 -241
  125. package/src/render/element.tsx +0 -28
  126. package/src/render/index.ts +0 -483
  127. package/src/render/loaders.ts +0 -117
  128. package/src/router.ts +0 -439
  129. /package/src/{render → server/render}/template.ts +0 -0
  130. /package/src/{runtime-env.ts → server/runtime-env.ts} +0 -0
@@ -1,9 +0,0 @@
1
- import MagicString from "magic-string";
2
- interface TransformResult {
3
- code: string;
4
- map: ReturnType<MagicString["generateMap"]> | null;
5
- removedServerCode: boolean;
6
- }
7
- export declare function deadCodeElimination(s: MagicString): MagicString;
8
- export declare function transformForClient(code: string, filename: string): TransformResult;
9
- export {};
@@ -1,15 +0,0 @@
1
- import type { buildHeadInjection } from "./shell";
2
- /** Minimal context passed to background / synthetic render helpers — only `request` is needed. */
3
- export interface LoaderContext {
4
- request: Request;
5
- }
6
- export declare function resolvePath(pattern: string, params: Record<string, string>): string;
7
- export declare function streamToString(stream: ReadableStream): Promise<string>;
8
- interface SplitTemplate {
9
- bodyPost: string;
10
- bodyPre: string;
11
- headPre: string;
12
- }
13
- export declare function splitTemplate(template: string): SplitTemplate;
14
- export declare function assembleHTML(template: string, headData: ReturnType<typeof buildHeadInjection>, reactHtml: string, data: Record<string, unknown> | undefined): string;
15
- export {};
@@ -1,95 +0,0 @@
1
- export interface ISRCacheEntry {
2
- generatedAt: number;
3
- html: string;
4
- revalidate: number;
5
- }
6
- export interface SsgCacheEntry {
7
- cachedAt: number;
8
- html: string;
9
- }
10
- export declare const isrCache: Map<string, ISRCacheEntry>;
11
- export declare const ssgCache: Map<string, SsgCacheEntry>;
12
- /**
13
- * Gets an ISR cache entry and refreshes its recency so it is treated as
14
- * recently used by the LRU eviction policy. Without this, a hot entry that
15
- * was written early would be evicted before a cold entry written later.
16
- */
17
- export declare function getISRCache(key: string): ISRCacheEntry | undefined;
18
- /**
19
- * Gets an SSG cache entry and refreshes its recency so it is treated as
20
- * recently used by the LRU eviction policy.
21
- */
22
- export declare function getSSGCache(key: string): SsgCacheEntry | undefined;
23
- /** Sets an ISR cache entry with LRU eviction. */
24
- export declare function setISRCache(key: string, entry: ISRCacheEntry): void;
25
- /** Sets an SSG cache entry with LRU eviction. */
26
- export declare function setSSGCache(key: string, entry: SsgCacheEntry): void;
27
- /** Set once at server startup from the CompileContext. */
28
- export declare function setBuildId(id: string): void;
29
- /** Returns the current deployment build ID, or empty string in dev / before set. */
30
- export declare function getBuildId(): string;
31
- /**
32
- * Wraps `fn` in a fresh per-request invalidation scope.
33
- * Call this around the entire Elysia request handle so that all lifecycle
34
- * hooks share an isolated invalidation Set.
35
- * @internal
36
- */
37
- export declare function _runWithRequestInvalidationScope<T>(fn: () => T): T;
38
- /**
39
- * Consume and clear all pending invalidation paths for the current request.
40
- * Called by the Elysia `onAfterHandle` hook to populate `X-Furin-Revalidate`.
41
- * @internal
42
- */
43
- export declare function consumePendingInvalidations(): string[];
44
- type CachePurger = (paths: string[]) => Promise<void>;
45
- /**
46
- * Register a CDN cache purger that will be called whenever `revalidatePath()`
47
- * is invoked. Intended for use by platform adapters (Vercel, Cloudflare, etc.).
48
- *
49
- * The purger is called fire-and-forget — errors are logged but do not affect
50
- * the HTTP response.
51
- *
52
- * @example
53
- * ```ts
54
- * // In a Vercel adapter:
55
- * import { setCachePurger } from "@teyik0/furin";
56
- * setCachePurger(async (paths) => {
57
- * await fetch("https://api.vercel.com/v1/edge-cache/purge", {
58
- * method: "POST",
59
- * headers: { Authorization: `Bearer ${process.env.VERCEL_TOKEN}` },
60
- * body: JSON.stringify({ urls: paths }),
61
- * });
62
- * });
63
- * ```
64
- */
65
- export declare function setCachePurger(fn: CachePurger): void;
66
- /** @internal */
67
- export declare function callCachePurger(paths: string[]): void;
68
- /**
69
- * Programmatically invalidate the server-side cache for a given path.
70
- *
71
- * - `type: 'page'` (default): exact URL match.
72
- * - `type: 'layout'`: the path itself plus all nested children (prefix match).
73
- *
74
- * Works for ISR and SSG routes. SSR routes are always fresh (no server-side
75
- * cache), but calling this still queues a client-side prefetch invalidation
76
- * via the `X-Furin-Revalidate` response header.
77
- *
78
- * If a CDN purger has been registered via `setCachePurger()`, it will also be
79
- * called asynchronously to purge the CDN edge cache.
80
- *
81
- * @returns `true` if at least one server-side cache entry was removed.
82
- *
83
- * @example
84
- * ```ts
85
- * // In an API route or webhook handler:
86
- * import { revalidatePath } from "@teyik0/furin";
87
- *
88
- * revalidatePath("/blog/my-post"); // invalidate a single page
89
- * revalidatePath("/blog", "layout"); // invalidate /blog + all children
90
- * ```
91
- */
92
- export declare function revalidatePath(path: string, type?: "page" | "layout"): boolean;
93
- /** @internal — resets all module state between tests */
94
- export declare function __resetCacheState(): void;
95
- export {};
@@ -1,4 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { RuntimeRoute } from "../client";
3
- import type { ResolvedRoute } from "../router";
4
- export declare function buildElement(route: ResolvedRoute, data: Record<string, unknown>, rootLayout: RuntimeRoute): ReactNode;
@@ -1,27 +0,0 @@
1
- import type { RootLayout } from "../router.ts";
2
- import { type SsgCacheEntry } from "./cache.ts";
3
- export { type LoaderContext, streamToString } from "./assemble.ts";
4
- export { buildElement } from "./element.tsx";
5
- export { type LoaderResult, runLoaders } from "./loaders.ts";
6
- import type { Context } from "elysia";
7
- import type { ResolvedRoute } from "../router.ts";
8
- interface RenderResult {
9
- headers: Record<string, string>;
10
- html: string;
11
- }
12
- export declare function renderToHTML(route: ResolvedRoute, ctx: Context, root: RootLayout): Promise<RenderResult>;
13
- export declare function renderToStream(route: ResolvedRoute, ctx: Context, root: RootLayout): Promise<ReadableStream | Response>;
14
- export declare function prerenderSSG(route: ResolvedRoute, params: Record<string, string>, root: RootLayout, origin?: string, basePath?: string): Promise<SsgCacheEntry | Response>;
15
- export declare function renderSSR(route: ResolvedRoute, ctx: Context, root: RootLayout): Promise<Response>;
16
- export declare function handleISR(route: ResolvedRoute, ctx: Context, root: RootLayout, buildId?: string): Promise<string | Response | undefined>;
17
- /**
18
- * Pre-renders all SSG routes that declare `staticParams` and populates the
19
- * in-memory cache before the first real request arrives.
20
- * Should be called from the Elysia `onStart` hook (production only).
21
- *
22
- * Uses a bounded worker pool (SSG_WARM_CONCURRENCY slots) so large sites
23
- * with many routes × param sets cannot exhaust memory or CPU during startup.
24
- * Failures are isolated per (route, params) pair and logged without aborting
25
- * the rest of the warm-up.
26
- */
27
- export declare function warmSSGCache(routes: ResolvedRoute[], root: RootLayout, origin: string): Promise<void>;
@@ -1,12 +0,0 @@
1
- import type { Context } from "elysia";
2
- import type { RuntimeRoute } from "../client";
3
- import type { ResolvedRoute } from "../router";
4
- export type LoaderResult = {
5
- type: "data";
6
- data: Record<string, unknown>;
7
- headers: Record<string, string>;
8
- } | {
9
- type: "redirect";
10
- response: Response;
11
- };
12
- export declare function runLoaders(route: ResolvedRoute, ctx: Context, _rootLayout: RuntimeRoute): Promise<LoaderResult>;
@@ -1,29 +0,0 @@
1
- import type { HeadOptions, MetaDescriptor } from "../client.ts";
2
- export declare function extractTitle(meta?: MetaDescriptor[]): string | undefined;
3
- export declare function isMetaTag(entry: MetaDescriptor): boolean;
4
- export declare function escapeHtml(str: string): string;
5
- export declare function safeJson(value: unknown): string;
6
- export declare function renderAttrs(obj: Record<string, string | undefined>): string;
7
- export declare function buildMetaParts(meta: MetaDescriptor[]): string[];
8
- export declare function buildLinkParts(links: NonNullable<HeadOptions["links"]>): string[];
9
- export declare function buildScriptParts(scripts: NonNullable<HeadOptions["scripts"]>): string[];
10
- export declare function buildStyleParts(styles: NonNullable<HeadOptions["styles"]>): string[];
11
- /**
12
- * Builds the string to inject into the <!--ssr-head--> placeholder.
13
- * Handles title, meta tags, links, inline scripts, and inline styles from
14
- * the page's `head()` function. CSS is handled by Bun (imported in user files).
15
- */
16
- export declare function buildHeadInjection(headData: HeadOptions | undefined): string;
17
- export declare function generateIndexHtml(): string;
18
- /**
19
- * Generates the production SSR template (index.html) with hashed asset paths.
20
- * Called after Bun.build() completes so we can inject the correct entry chunk
21
- * and CSS paths derived from result.outputs.
22
- *
23
- * @param buildId - Short hash identifying this specific build. Injected as a
24
- * `<meta name="furin-build-id">` tag so the client can detect stale deploys.
25
- * @param faviconHref - Absolute href for the favicon (e.g. "/furin/favicon.ico").
26
- * When provided, a `<link rel="icon">` tag is injected so browsers can locate
27
- * the favicon even when the site is served from a sub-path.
28
- */
29
- export declare function generateProdIndexHtml(entryChunk: string, cssChunks: string[], buildId?: string, faviconHref?: string): string;
@@ -1,6 +0,0 @@
1
- export declare function getDevTemplate(origin: string): Promise<string>;
2
- export declare function setProductionTemplatePath(path: string | null): void;
3
- export declare function setProductionTemplateContent(content: string): void;
4
- export declare function getProductionTemplate(): string | null;
5
- /** @internal test-only — resets all template state */
6
- export declare function __resetTemplateState(): void;
package/dist/router.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import { type AnyElysia, type Context } from "elysia";
2
- import type { AnySchema } from "elysia/types";
3
- import type { RuntimePage, RuntimeRoute } from "./client.ts";
4
- import { type CompileContext } from "./internal.ts";
5
- export interface ResolvedRoute {
6
- isrCache?: {
7
- html: string;
8
- generatedAt: number;
9
- revalidate: number;
10
- };
11
- mode: "ssr" | "ssg" | "isr";
12
- page: RuntimePage;
13
- path: string;
14
- pattern: string;
15
- routeChain: RuntimeRoute[];
16
- ssgHtml?: string;
17
- }
18
- export interface RootLayout {
19
- path: string;
20
- route: RuntimeRoute;
21
- }
22
- export declare function loadProdRoutes(ctx: CompileContext): {
23
- root: RootLayout;
24
- routes: ResolvedRoute[];
25
- };
26
- export declare function scanPages(pagesDir: string): Promise<{
27
- root: RootLayout;
28
- routes: ResolvedRoute[];
29
- }>;
30
- export declare function scanRootLayout(pagesDir: string): Promise<RootLayout>;
31
- /** @internal Exported for unit testing. */
32
- export declare function queryDefaultRedirectHook({ request, query, status, set }: Context): import("elysia").ElysiaCustomStatusResponse<"Found", "Found", 302> | undefined;
33
- /**
34
- * Merges TObject schemas from all routeChain entries for a given key.
35
- * Properties are spread left-to-right (leaf wins on key conflict).
36
- * Object-level options (additionalProperties, $id, description, …) are also
37
- * merged with the same leaf-wins semantics so they are not silently dropped.
38
- * Returns undefined when no entry in the chain defines the key.
39
- *
40
- * @internal Exported for unit testing.
41
- */
42
- export declare function mergeRouteSchemas(routeChain: RuntimeRoute[], key: "params" | "query"): AnySchema | undefined;
43
- export declare function createRoutePlugin(route: ResolvedRoute, root: RootLayout, buildId?: string): AnyElysia;
44
- export declare function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr";
45
- export declare function filePathToPattern(path: string): string;