@teyik0/furin 0.4.0-alpha.2 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/compile-entry.d.ts +2 -1
- package/dist/build/compile-entry.ts +17 -13
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +5 -1
- package/dist/build/entry-template.ts +24 -5
- package/dist/build/index.js +753 -453
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/cache.d.ts +1 -0
- package/dist/cache.js +185 -0
- package/dist/cli/index.js +766 -466
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +221 -11
- package/dist/client/sync.d.ts +1 -0
- package/dist/config.d.ts +22 -21
- package/dist/config.js +1 -1
- package/dist/define-route.d.ts +273 -1009
- package/dist/furin.d.ts +20 -5
- package/dist/furin.js +6222 -5383
- package/dist/plugin/routes.d.ts +6 -0
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +1 -1
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/context-logger.d.ts +2 -2
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +7 -0
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +2537 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +5 -0
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/schemas.d.ts +1 -0
- package/dist/server/sync/index.js +794 -116
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/stream.d.ts +34 -49
- package/dist/shared/elysia-contract.d.ts +8 -14
- package/package.json +13 -7
- package/src/adapter/README.md +9 -2
- package/src/adapter/bun.ts +73 -27
- package/src/adapter/package.ts +6 -2
- package/src/adapter/runtime-build.ts +11 -4
- package/src/adapter/static.ts +8 -6
- package/src/adapter/vercel.ts +49 -30
- package/src/build/client.ts +18 -1
- package/src/build/compile-entry.ts +17 -13
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +24 -5
- package/src/build/index.ts +0 -5
- package/src/build/production-instrumentation.ts +2 -2
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +3 -1
- package/src/build/ssg-cache.ts +5 -10
- package/src/build/virtual-entry.ts +5 -4
- package/src/cache.ts +12 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +5 -2
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/sync.ts +1 -0
- package/src/config.ts +3 -2
- package/src/define-route.ts +266 -128
- package/src/furin.ts +138 -149
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +85 -29
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +74 -42
- package/src/server/browser-events/plugin.ts +6 -1
- package/src/server/cache/invalidation.ts +61 -20
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/context-logger.ts +5 -5
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev-page-plugin.ts +54 -10
- package/src/server/evlog.ts +99 -0
- package/src/server/internal.ts +7 -0
- package/src/server/render/isr.ts +480 -132
- package/src/server/render/loaders.ts +18 -12
- package/src/server/render/not-found.ts +4 -4
- package/src/server/render/ppr-document.ts +2 -2
- package/src/server/render/ppr-route.ts +193 -7
- package/src/server/render/ssg.ts +148 -4
- package/src/server/render/ssr.ts +4 -6
- package/src/server/render/static-params.ts +174 -0
- package/src/server/router/defined-route.ts +2 -1
- package/src/server/router/hmr.ts +2 -0
- package/src/server/router/plugin.ts +44 -35
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/sync/plugin.ts +14 -10
- package/src/server/sync/response.ts +3 -3
- package/src/shared/elysia-contract.ts +23 -25
package/src/build/shared.ts
CHANGED
|
@@ -56,7 +56,9 @@ export function toBuildRouteManifestEntry(
|
|
|
56
56
|
mode: route.mode,
|
|
57
57
|
pagePath: toPosixPath(relative(rootDir, route.path)),
|
|
58
58
|
hasLayout: route.routeChain.some((entry) => !!entry.layout),
|
|
59
|
-
hasStaticParams:
|
|
59
|
+
hasStaticParams:
|
|
60
|
+
route.page.staticParams !== undefined ||
|
|
61
|
+
route.routeChain.some((entry) => entry.staticParams !== undefined),
|
|
60
62
|
revalidate: resolveRouteRevalidate(route.page) ?? null,
|
|
61
63
|
};
|
|
62
64
|
}
|
package/src/build/ssg-cache.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
|
3
3
|
import { resolvePath } from "../server/render/assemble.ts";
|
|
4
4
|
import { prerenderRoute, prerenderSSG } from "../server/render/index.ts";
|
|
5
5
|
import { hasRequestLoader } from "../server/render/loaders.ts";
|
|
6
|
+
import { hasStaticParams, resolveStaticParams } from "../server/render/static-params.ts";
|
|
6
7
|
import { buildRouteMatcher } from "../server/router/patterns.ts";
|
|
7
8
|
import { createSearchRouteMetadata } from "../server/router/schemas.ts";
|
|
8
9
|
import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
|
|
@@ -52,14 +53,8 @@ export async function buildRoutePrerenders(
|
|
|
52
53
|
let paramSets: Record<string, string>[];
|
|
53
54
|
if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
54
55
|
paramSets = [{}];
|
|
55
|
-
} else if (route
|
|
56
|
-
|
|
57
|
-
if (!Array.isArray(resolvedParams)) {
|
|
58
|
-
throw new TypeError(
|
|
59
|
-
`[furin] staticParams() for "${route.pattern}" must return an array.`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
paramSets = resolvedParams;
|
|
56
|
+
} else if (hasStaticParams(route)) {
|
|
57
|
+
paramSets = (await resolveStaticParams(route, origin)) ?? [];
|
|
63
58
|
} else {
|
|
64
59
|
continue;
|
|
65
60
|
}
|
|
@@ -102,10 +97,10 @@ export async function buildSSGCacheSnapshot(
|
|
|
102
97
|
const searchRoutes = createSearchRouteMetadata(routes);
|
|
103
98
|
|
|
104
99
|
for (const route of routes) {
|
|
105
|
-
if (route.mode !== "ssg" || !route
|
|
100
|
+
if (route.mode !== "ssg" || !hasStaticParams(route) || hasRequestLoader(route)) {
|
|
106
101
|
continue;
|
|
107
102
|
}
|
|
108
|
-
const paramSets = await route
|
|
103
|
+
const paramSets = (await resolveStaticParams(route, origin)) ?? [];
|
|
109
104
|
for (const params of paramSets) {
|
|
110
105
|
const result = await prerenderSSG(
|
|
111
106
|
route,
|
|
@@ -11,14 +11,15 @@ export function createVirtualBuildEntry(
|
|
|
11
11
|
source: string,
|
|
12
12
|
loader: Bun.Loader
|
|
13
13
|
): VirtualBuildEntry {
|
|
14
|
+
const normalizedEntrypoint = entrypoint.replaceAll("\\", "/");
|
|
14
15
|
const entrypointFilter = new RegExp(
|
|
15
|
-
`^${
|
|
16
|
+
`^${normalizedEntrypoint.replace(REGEX_SPECIAL_CHARACTERS_RE, "\\$&")}$`
|
|
16
17
|
);
|
|
17
18
|
return {
|
|
18
|
-
entrypoint,
|
|
19
|
-
files: { [
|
|
19
|
+
entrypoint: normalizedEntrypoint,
|
|
20
|
+
files: { [normalizedEntrypoint]: source },
|
|
20
21
|
plugin: {
|
|
21
|
-
name: `furin-virtual-entry:${
|
|
22
|
+
name: `furin-virtual-entry:${normalizedEntrypoint}`,
|
|
22
23
|
setup(build) {
|
|
23
24
|
build.onLoad({ filter: entrypointFilter }, () => ({ contents: source, loader }));
|
|
24
25
|
},
|
package/src/cache.ts
CHANGED
|
@@ -5,6 +5,18 @@ import {
|
|
|
5
5
|
type RuntimeCacheSetOptions as RuntimeCacheSetOptionsContract,
|
|
6
6
|
} from "./server/cache/runtime-cache.ts";
|
|
7
7
|
|
|
8
|
+
// biome-ignore lint/performance/noBarrelFile: this is the intentional public cache entrypoint.
|
|
9
|
+
export {
|
|
10
|
+
createMemoryPageCache,
|
|
11
|
+
type PageCacheAdapter,
|
|
12
|
+
type PageCacheEntry,
|
|
13
|
+
type PageCacheIdentity,
|
|
14
|
+
type PageCacheInvalidation,
|
|
15
|
+
type PageCacheInvalidationResult,
|
|
16
|
+
type PageCacheLease,
|
|
17
|
+
type PageCacheMode,
|
|
18
|
+
} from "./server/cache/page-cache.ts";
|
|
19
|
+
|
|
8
20
|
export type RuntimeCache = RuntimeCacheContract;
|
|
9
21
|
export type RuntimeCacheOptions = RuntimeCacheOptionsContract;
|
|
10
22
|
export type RuntimeCacheSetOptions = RuntimeCacheSetOptionsContract;
|
package/src/cli/config.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { Validator } from "elysia";
|
|
4
5
|
import { configSchema, type FurinConfig } from "../config.ts";
|
|
5
|
-
import { TypeCompiler } from "../shared/elysia-contract.ts";
|
|
6
6
|
|
|
7
|
-
const compiledConfigSchema =
|
|
7
|
+
const compiledConfigSchema = Validator.create(configSchema);
|
|
8
8
|
|
|
9
9
|
const DEFAULT_CONFIG_FILENAMES = [
|
|
10
10
|
"furin.config.ts",
|
|
@@ -57,7 +57,7 @@ export async function loadCliConfig(
|
|
|
57
57
|
if (!compiledConfigSchema.Check(configToValidate)) {
|
|
58
58
|
const [firstError] = compiledConfigSchema.Errors(configToValidate);
|
|
59
59
|
throw new Error(
|
|
60
|
-
`[furin] Invalid config at ${configPath}: ${firstError?.message ?? "unknown error"} (path: ${firstError?.
|
|
60
|
+
`[furin] Invalid config at ${configPath}: ${firstError?.message ?? "unknown error"} (path: ${firstError?.instancePath ?? "/"})`
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
|
package/src/cli/index.ts
CHANGED
|
@@ -96,8 +96,11 @@ if (command === "preview") {
|
|
|
96
96
|
};
|
|
97
97
|
const config = await loadCliConfig(process.cwd(), values.config);
|
|
98
98
|
const port = values.port === undefined ? 3000 : Number(values.port);
|
|
99
|
-
if (
|
|
100
|
-
|
|
99
|
+
if (
|
|
100
|
+
(values.port !== undefined && !/^\d+$/.test(values.port)) ||
|
|
101
|
+
!(Number.isInteger(port) && port >= 0 && port <= 65_535)
|
|
102
|
+
) {
|
|
103
|
+
bail(`Invalid preview port "${values.port}". Expected an integer between 0 and 65535.`);
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
const distDir = resolve(config.rootDir, values.dir ?? config.static?.outDir ?? "dist");
|
|
@@ -6,6 +6,14 @@ export type RuntimeData = Record<string, unknown>;
|
|
|
6
6
|
|
|
7
7
|
type Awaitable<T> = Promise<T> | T;
|
|
8
8
|
|
|
9
|
+
export interface RuntimeParams {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type RuntimeStaticParams = (
|
|
14
|
+
context: RuntimeData & { params: RuntimeParams }
|
|
15
|
+
) => Awaitable<readonly RuntimeParams[]>;
|
|
16
|
+
|
|
9
17
|
export interface RuntimeRoute {
|
|
10
18
|
__type: "FURIN_ROUTE";
|
|
11
19
|
layout?: React.FC<RuntimeData & { children: React.ReactNode }>;
|
|
@@ -17,6 +25,7 @@ export interface RuntimeRoute {
|
|
|
17
25
|
requestLoader?: (ctx: RequestLoaderContext) => Awaitable<object>;
|
|
18
26
|
revalidate?: number;
|
|
19
27
|
sourcePath?: string;
|
|
28
|
+
staticParams?: RuntimeStaticParams;
|
|
20
29
|
tags?: string[];
|
|
21
30
|
}
|
|
22
31
|
|
|
@@ -28,6 +37,6 @@ export interface RuntimePage {
|
|
|
28
37
|
loader?: (ctx: RuntimeData) => Awaitable<RuntimeData>;
|
|
29
38
|
mode?: RenderingMode;
|
|
30
39
|
revalidate?: number;
|
|
31
|
-
staticParams?:
|
|
40
|
+
staticParams?: RuntimeStaticParams;
|
|
32
41
|
tags?: string[];
|
|
33
42
|
}
|
package/src/client/sync.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BunPlugin } from "bun";
|
|
2
2
|
import { t } from "elysia";
|
|
3
|
+
import type { Static } from "typebox";
|
|
3
4
|
|
|
4
|
-
export const BUILD_TARGETS = ["bun", "
|
|
5
|
+
export const BUILD_TARGETS = ["bun", "vercel", "static", "package"] as const;
|
|
5
6
|
|
|
6
7
|
export type BuildTarget = (typeof BUILD_TARGETS)[number];
|
|
7
8
|
|
|
@@ -101,7 +102,7 @@ export const configSchema = t.Object({
|
|
|
101
102
|
|
|
102
103
|
export type FurinPlugin = BunPlugin & { buildOnly?: boolean };
|
|
103
104
|
|
|
104
|
-
export type FurinConfig =
|
|
105
|
+
export type FurinConfig = Static<typeof configSchema> & {
|
|
105
106
|
plugins?: FurinPlugin[];
|
|
106
107
|
static?: StaticExportConfig;
|
|
107
108
|
};
|