@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.
Files changed (100) hide show
  1. package/dist/build/compile-entry.d.ts +2 -1
  2. package/dist/build/compile-entry.ts +17 -13
  3. package/dist/build/elysia-aot.d.ts +9 -0
  4. package/dist/build/entry-template.d.ts +5 -1
  5. package/dist/build/entry-template.ts +24 -5
  6. package/dist/build/index.js +753 -453
  7. package/dist/build/server-app-entry.d.ts +12 -0
  8. package/dist/cache.d.ts +1 -0
  9. package/dist/cache.js +185 -0
  10. package/dist/cli/index.js +766 -466
  11. package/dist/client/internal/runtime-types.d.ts +8 -1
  12. package/dist/client/link.js +221 -11
  13. package/dist/client/sync.d.ts +1 -0
  14. package/dist/config.d.ts +22 -21
  15. package/dist/config.js +1 -1
  16. package/dist/define-route.d.ts +273 -1009
  17. package/dist/furin.d.ts +20 -5
  18. package/dist/furin.js +6222 -5383
  19. package/dist/plugin/routes.d.ts +6 -0
  20. package/dist/server/assets/production.d.ts +3 -0
  21. package/dist/server/auto-invalidate/plugin.d.ts +8 -24
  22. package/dist/server/auto-invalidate/runtime.d.ts +2 -2
  23. package/dist/server/cache/invalidation.d.ts +1 -1
  24. package/dist/server/cache/page-cache-state.d.ts +5 -0
  25. package/dist/server/cache/page-cache.d.ts +53 -0
  26. package/dist/server/cache/redis/index.d.ts +39 -0
  27. package/dist/server/cache/redis/index.js +396 -0
  28. package/dist/server/cache/redis/scripts.d.ts +6 -0
  29. package/dist/server/context-logger.d.ts +2 -2
  30. package/dist/server/dev/runtime.production.d.ts +1 -0
  31. package/dist/server/dev-page-plugin.d.ts +7 -0
  32. package/dist/server/evlog.d.ts +14 -0
  33. package/dist/server/internal.d.ts +6 -0
  34. package/dist/server/internal.js +2537 -0
  35. package/dist/server/render/not-found.d.ts +1 -1
  36. package/dist/server/render/ssg.d.ts +5 -0
  37. package/dist/server/render/static-params.d.ts +4 -0
  38. package/dist/server/router/defined-route.d.ts +1 -1
  39. package/dist/server/router/schemas.d.ts +1 -0
  40. package/dist/server/sync/index.js +794 -116
  41. package/dist/server/sync/plugin.d.ts +31 -158
  42. package/dist/server/sync/stream.d.ts +34 -49
  43. package/dist/shared/elysia-contract.d.ts +8 -14
  44. package/package.json +13 -7
  45. package/src/adapter/README.md +9 -2
  46. package/src/adapter/bun.ts +73 -27
  47. package/src/adapter/package.ts +6 -2
  48. package/src/adapter/runtime-build.ts +11 -4
  49. package/src/adapter/static.ts +8 -6
  50. package/src/adapter/vercel.ts +49 -30
  51. package/src/build/client.ts +18 -1
  52. package/src/build/compile-entry.ts +17 -13
  53. package/src/build/elysia-aot.ts +102 -0
  54. package/src/build/entry-template.ts +24 -5
  55. package/src/build/index.ts +0 -5
  56. package/src/build/production-instrumentation.ts +2 -2
  57. package/src/build/server-app-entry.ts +60 -0
  58. package/src/build/shared.ts +3 -1
  59. package/src/build/ssg-cache.ts +5 -10
  60. package/src/build/virtual-entry.ts +5 -4
  61. package/src/cache.ts +12 -0
  62. package/src/cli/config.ts +3 -3
  63. package/src/cli/index.ts +5 -2
  64. package/src/client/internal/runtime-types.ts +10 -1
  65. package/src/client/sync.ts +1 -0
  66. package/src/config.ts +3 -2
  67. package/src/define-route.ts +266 -128
  68. package/src/furin.ts +138 -149
  69. package/src/plugin/route-config-autofix.ts +11 -2
  70. package/src/plugin/routes.ts +85 -29
  71. package/src/server/assets/production.ts +99 -0
  72. package/src/server/auto-invalidate/plugin.ts +4 -4
  73. package/src/server/auto-invalidate/runtime.ts +74 -42
  74. package/src/server/browser-events/plugin.ts +6 -1
  75. package/src/server/cache/invalidation.ts +61 -20
  76. package/src/server/cache/page-cache-state.ts +22 -0
  77. package/src/server/cache/page-cache.ts +300 -0
  78. package/src/server/cache/redis/index.ts +350 -0
  79. package/src/server/cache/redis/scripts.ts +160 -0
  80. package/src/server/context-logger.ts +5 -5
  81. package/src/server/dev/runtime.production.ts +4 -0
  82. package/src/server/dev-page-plugin.ts +54 -10
  83. package/src/server/evlog.ts +99 -0
  84. package/src/server/internal.ts +7 -0
  85. package/src/server/render/isr.ts +480 -132
  86. package/src/server/render/loaders.ts +18 -12
  87. package/src/server/render/not-found.ts +4 -4
  88. package/src/server/render/ppr-document.ts +2 -2
  89. package/src/server/render/ppr-route.ts +193 -7
  90. package/src/server/render/ssg.ts +148 -4
  91. package/src/server/render/ssr.ts +4 -6
  92. package/src/server/render/static-params.ts +174 -0
  93. package/src/server/router/defined-route.ts +2 -1
  94. package/src/server/router/hmr.ts +2 -0
  95. package/src/server/router/plugin.ts +44 -35
  96. package/src/server/router/schema-merge.ts +1 -1
  97. package/src/server/router/schemas.ts +174 -61
  98. package/src/server/sync/plugin.ts +14 -10
  99. package/src/server/sync/response.ts +3 -3
  100. package/src/shared/elysia-contract.ts +23 -25
@@ -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: !!route.page?.staticParams,
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
  }
@@ -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.page.staticParams) {
56
- const resolvedParams = await route.page.staticParams();
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.page.staticParams || hasRequestLoader(route)) {
100
+ if (route.mode !== "ssg" || !hasStaticParams(route) || hasRequestLoader(route)) {
106
101
  continue;
107
102
  }
108
- const paramSets = await route.page.staticParams();
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
- `^${entrypoint.replace(REGEX_SPECIAL_CHARACTERS_RE, "\\$&")}$`
16
+ `^${normalizedEntrypoint.replace(REGEX_SPECIAL_CHARACTERS_RE, "\\$&")}$`
16
17
  );
17
18
  return {
18
- entrypoint,
19
- files: { [entrypoint]: source },
19
+ entrypoint: normalizedEntrypoint,
20
+ files: { [normalizedEntrypoint]: source },
20
21
  plugin: {
21
- name: `furin-virtual-entry:${entrypoint}`,
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 = TypeCompiler.Compile(configSchema);
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?.path ?? "/"})`
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 (!(Number.isInteger(port) && port > 0 && port <= 65_535)) {
100
- bail(`Invalid preview port "${values.port}". Expected an integer between 1 and 65535.`);
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?: () => Awaitable<Record<string, string>[]>;
40
+ staticParams?: RuntimeStaticParams;
32
41
  tags?: string[];
33
42
  }
@@ -2,6 +2,7 @@ import { useCallback } from "react";
2
2
 
3
3
  export interface SyncMutationHeaders {
4
4
  "Idempotency-Key": string;
5
+ [header: string]: string;
5
6
  }
6
7
 
7
8
  export interface SyncMutationOptions {
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", "node", "vercel", "cloudflare", "static", "package"] as const;
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 = (typeof configSchema)["static"] & {
105
+ export type FurinConfig = Static<typeof configSchema> & {
105
106
  plugins?: FurinPlugin[];
106
107
  static?: StaticExportConfig;
107
108
  };