@teyik0/furin 0.2.0-alpha.5 → 0.3.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/README.md +2 -3
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/bun-build.d.ts +3 -0
- package/dist/build/entry-template.d.ts +2 -0
- package/dist/build/entry-template.ts +3 -0
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +6944 -5067
- package/dist/build/production-instrumentation.d.ts +1 -0
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +1 -0
- package/dist/cli/index.js +7874 -5971
- package/dist/client/boundaries.d.ts +4 -4
- package/dist/client/internal/runtime-types.d.ts +30 -0
- package/dist/client/link.d.ts +2 -1
- package/dist/client/link.js +712 -338
- package/dist/client/router/boundary-tree.d.ts +1 -1
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +5 -1
- package/dist/client/router/sync-catch-up.d.ts +4 -4
- package/dist/client/router/types.d.ts +2 -2
- package/dist/client-only.d.ts +1 -0
- package/dist/client-only.js +1 -0
- package/dist/client.d.ts +108 -111
- package/dist/client.js +16 -17
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/devtools/devtools-element.d.ts +1 -0
- package/dist/devtools/protocol.d.ts +119 -0
- package/dist/furin.d.ts +7 -6
- package/dist/furin.js +6547 -3187
- package/dist/isomorphic.d.ts +18 -0
- package/dist/plugin/binding-scope.d.ts +2 -0
- package/dist/plugin/dead-code-elimination.d.ts +3 -0
- package/dist/plugin/index.js +933 -423
- package/dist/plugin/transform-client.d.ts +0 -2
- package/dist/plugin/transform-isomorphic.d.ts +9 -0
- package/dist/rsc/build/environment.d.ts +2 -0
- package/dist/rsc/build/index.d.ts +15 -0
- package/dist/rsc/client-codec.d.ts +1 -0
- package/dist/rsc/codec.d.ts +4 -0
- package/dist/rsc/flight-drain.d.ts +11 -0
- package/dist/rsc/render-error.d.ts +17 -0
- package/dist/rsc/server-codec.d.ts +2 -0
- package/dist/rsc/server-codec.js +24 -0
- package/dist/rsc/shared.d.ts +30 -0
- package/dist/rsc/symbols.d.ts +2 -0
- package/dist/rsc/transport-benchmark.d.ts +13 -0
- package/dist/rsc/version.d.ts +7 -0
- package/dist/rsc-client.d.ts +4 -0
- package/dist/rsc-client.js +166 -0
- package/dist/rsc-server.d.ts +11 -0
- package/dist/rsc.d.ts +11 -0
- package/dist/rsc.js +353 -0
- package/dist/server/cache/index.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr-ssg.d.ts +5 -1
- package/dist/server/cache/isr.d.ts +9 -0
- package/dist/server/cache/route-cache.d.ts +10 -8
- package/dist/server/cache/store-view.d.ts +7 -7
- package/dist/server/dev-page-plugin.d.ts +4 -0
- package/dist/server/devtools/hub.d.ts +11 -0
- package/dist/server/devtools/instrumentation.d.ts +22 -0
- package/dist/server/devtools/instrumentation.production.d.ts +44 -0
- package/dist/server/devtools/plugin.d.ts +3 -0
- package/dist/server/devtools/request-context.d.ts +6 -0
- package/dist/server/internal.d.ts +2 -0
- package/dist/server/internal.js +3 -3
- package/dist/server/lang-detect.d.ts +1 -0
- package/dist/server/render/assemble.d.ts +4 -0
- package/dist/server/render/element.d.ts +1 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +6 -2
- package/dist/server/render/loaders.d.ts +8 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-route.d.ts +8 -0
- package/dist/server/render/route-frame-transport.d.ts +2 -0
- package/dist/server/render/shell.ts +0 -1
- package/dist/server/render/ssr.d.ts +2 -3
- package/dist/server/router/discovery.d.ts +1 -1
- package/dist/server/router/hmr.d.ts +1 -1
- package/dist/server/router/index.d.ts +2 -1
- package/dist/server/router/index.js +23 -23
- package/dist/server/router/index.ts +1 -1
- package/dist/server/router/patterns.d.ts +1 -1
- package/dist/server/router/plugin.d.ts +4 -7
- package/dist/server/router/schema-merge.d.ts +3 -0
- package/dist/server/router/schemas.d.ts +12 -7
- package/dist/server/router/types.d.ts +1 -1
- package/dist/server/runtime-env.js +2 -2
- package/dist/server/sync/adapter.d.ts +45 -26
- package/dist/server/sync/config.d.ts +5 -9
- package/dist/server/sync/fingerprint.d.ts +2 -1
- package/dist/server/sync/index.d.ts +15 -4
- package/dist/server/sync/index.js +2868 -0
- package/dist/server/sync/notifier.d.ts +18 -0
- package/dist/server/sync/plugin.d.ts +53 -54
- package/dist/server/sync/postgres/index.d.ts +19 -0
- package/dist/server/sync/postgres/index.js +252 -0
- package/dist/server/sync/postgres/migrate.d.ts +2 -0
- package/dist/server/sync/postgres/migrate.js +16 -0
- package/dist/server/sync/postgres/migration.sql +66 -0
- package/dist/server/sync/redis/index.d.ts +30 -0
- package/dist/server/sync/redis/index.js +336 -0
- package/dist/server/sync/redis/scripts.d.ts +4 -0
- package/dist/server/sync/response.d.ts +10 -1
- package/dist/server/sync/runtime.d.ts +6 -0
- package/dist/server/sync/sqlite/index.d.ts +20 -0
- package/dist/server/sync/sqlite/index.js +250 -0
- package/dist/server/sync/stream.d.ts +12 -11
- package/dist/server-only.d.ts +1 -0
- package/dist/server-only.js +1 -0
- package/dist/shared/parser.d.ts +2 -0
- package/dist/shared/route-frame.d.ts +49 -0
- package/dist/shared/utils/index.d.ts +1 -1
- package/package.json +54 -12
- package/src/adapter/bun.ts +73 -16
- package/src/adapter/package.ts +3 -1
- package/src/adapter/static.ts +94 -48
- package/src/build/bun-build.ts +11 -0
- package/src/build/client.ts +22 -24
- package/src/build/entry-template.ts +3 -0
- package/src/build/hydrate.ts +33 -8
- package/src/build/index.ts +12 -0
- package/src/build/production-instrumentation.ts +14 -0
- package/src/build/route-types.ts +7 -8
- package/src/build/scan-server.ts +3 -2
- package/src/build/ssg-cache.ts +7 -2
- package/src/build/types.ts +1 -0
- package/src/cli/index.ts +53 -22
- package/src/client/boundaries.tsx +42 -18
- package/src/client/default-screens.tsx +4 -4
- package/src/client/internal/runtime-types.ts +31 -0
- package/src/client/link.tsx +35 -37
- package/src/client/router/boundary-tree.tsx +2 -2
- package/src/client/router/context.ts +13 -9
- package/src/client/router/index.ts +3 -0
- package/src/client/router/link-utils.ts +66 -3
- package/src/client/router/navigation.ts +9 -15
- package/src/client/router/provider.tsx +74 -52
- package/src/client/router/search/index.ts +5 -7
- package/src/client/router/search-store.ts +5 -1
- package/src/client/router/spa-response.ts +3 -4
- package/src/client/router/sync-catch-up.ts +9 -8
- package/src/client/router/types.ts +2 -2
- package/src/client/sync.ts +3 -2
- package/src/client-only.ts +1 -0
- package/src/client.ts +221 -174
- package/src/devtools/devtools-element.js +884 -0
- package/src/devtools/protocol.ts +139 -0
- package/src/furin.ts +185 -96
- package/src/isomorphic.ts +66 -0
- package/src/plugin/binding-scope.ts +158 -0
- package/src/plugin/dead-code-elimination.ts +202 -0
- package/src/plugin/index.ts +14 -18
- package/src/plugin/transform-client.ts +237 -273
- package/src/plugin/transform-isomorphic.ts +464 -0
- package/src/rsc/build/environment.ts +30 -0
- package/src/rsc/build/index.ts +94 -0
- package/src/rsc/client-codec.ts +11 -0
- package/src/rsc/codec.ts +85 -0
- package/src/rsc/flight-drain.ts +68 -0
- package/src/rsc/react-server-dom-webpack.d.ts +23 -0
- package/src/rsc/render-error.ts +120 -0
- package/src/rsc/server-codec.ts +25 -0
- package/src/rsc/shared.tsx +113 -0
- package/src/rsc/symbols.ts +2 -0
- package/src/rsc/transport-benchmark.ts +73 -0
- package/src/rsc/version.ts +57 -0
- package/src/rsc-client.ts +12 -0
- package/src/rsc-server.tsx +91 -0
- package/src/rsc.tsx +75 -0
- package/src/server/auto-invalidate/runtime.ts +32 -6
- package/src/server/cache/dev-loader.ts +70 -10
- package/src/server/cache/index.ts +7 -3
- package/src/server/cache/invalidation.ts +33 -15
- package/src/server/cache/isr-ssg.ts +12 -3
- package/src/server/cache/isr.ts +84 -9
- package/src/server/cache/route-cache.ts +49 -36
- package/src/server/cache/store-view.ts +7 -7
- package/src/server/context-logger.ts +7 -7
- package/src/server/dev-page-plugin.ts +8 -6
- package/src/server/devtools/hub.ts +64 -0
- package/src/server/devtools/instrumentation.production.ts +80 -0
- package/src/server/devtools/instrumentation.ts +72 -0
- package/src/server/devtools/plugin.ts +267 -0
- package/src/server/devtools/request-context.ts +76 -0
- package/src/server/instance.ts +1 -1
- package/src/server/internal.ts +2 -0
- package/src/server/lang-detect.ts +14 -10
- package/src/server/render/assemble.ts +73 -10
- package/src/server/render/element.tsx +11 -8
- package/src/server/render/index.ts +6 -2
- package/src/server/render/isr.ts +154 -110
- package/src/server/render/loaders.ts +259 -45
- package/src/server/render/not-found.ts +10 -15
- package/src/server/render/ppr-route.ts +146 -0
- package/src/server/render/route-frame-transport.ts +62 -0
- package/src/server/render/shell.ts +0 -1
- package/src/server/render/ssg.ts +6 -5
- package/src/server/render/ssr.ts +155 -67
- package/src/server/render/template.ts +2 -1
- package/src/server/router/discovery.ts +39 -22
- package/src/server/router/hmr.ts +15 -13
- package/src/server/router/index.ts +1 -1
- package/src/server/router/patterns.ts +16 -15
- package/src/server/router/plugin.ts +151 -158
- package/src/server/router/schema-merge.ts +52 -0
- package/src/server/router/schemas.ts +55 -73
- package/src/server/router/types.ts +1 -1
- package/src/server/sync/adapter.ts +44 -28
- package/src/server/sync/config.ts +9 -27
- package/src/server/sync/fingerprint.ts +8 -3
- package/src/server/sync/index.ts +37 -13
- package/src/server/sync/notifier.ts +109 -0
- package/src/server/sync/plugin.ts +184 -89
- package/src/server/sync/postgres/index.ts +301 -0
- package/src/server/sync/postgres/migrate.ts +15 -0
- package/src/server/sync/postgres/migration.sql +66 -0
- package/src/server/sync/redis/index.ts +342 -0
- package/src/server/sync/redis/scripts.ts +74 -0
- package/src/server/sync/response.ts +141 -16
- package/src/server/sync/runtime.ts +27 -0
- package/src/server/sync/sql.d.ts +4 -0
- package/src/server/sync/sqlite/index.ts +337 -0
- package/src/server/sync/sqlite/migration.sql +70 -0
- package/src/server/sync/stream.ts +137 -81
- package/src/server-only.ts +1 -0
- package/src/shared/await.tsx +4 -4
- package/src/shared/deferred-ndjson.ts +34 -6
- package/src/shared/digest.ts +2 -2
- package/src/shared/parser.ts +5 -0
- package/src/shared/route-frame.ts +429 -0
- package/src/shared/search-params.ts +7 -7
- package/src/shared/utils/index.ts +5 -3
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/sync/memory-adapter.d.ts +0 -17
- package/src/server/dev-inspector.ts +0 -60
- package/src/server/sync/memory-adapter.ts +0 -196
package/src/server/router/hmr.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noAwaitInLoops: HMR polling and invalidation are intentionally sequential
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import type { Context } from "elysia";
|
|
3
|
-
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
4
|
+
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
4
5
|
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
5
6
|
import { collectRouteChainFromRoute, isFurinPage, isFurinRoute } from "../../shared/utils/index.ts";
|
|
6
7
|
import { autoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
@@ -12,9 +13,11 @@ import {
|
|
|
12
13
|
setDevISRLoaderCache,
|
|
13
14
|
setDevSSGLoaderCache,
|
|
14
15
|
} from "../cache/dev-loader.ts";
|
|
16
|
+
import { pathWithRequestSearch } from "../cache/route-cache.ts";
|
|
15
17
|
import { type CompileContext, getCompileContext } from "../internal.ts";
|
|
16
18
|
import { resolvePath } from "../render/assemble.ts";
|
|
17
|
-
import { type LoaderResult,
|
|
19
|
+
import { type LoaderResult, runLoaders } from "../render/loaders.ts";
|
|
20
|
+
import { renderSSR } from "../render/ssr.ts";
|
|
18
21
|
import { collectRouteTags, getSourceModuleCandidates, isModuleNotFoundError } from "./discovery.ts";
|
|
19
22
|
import { collectIntermediateLayoutDirs, resolveMode } from "./patterns.ts";
|
|
20
23
|
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
@@ -78,8 +81,6 @@ async function importFreshLayoutRouteModule(
|
|
|
78
81
|
return freshMod;
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
|
|
82
|
-
return;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
function patchRouteEntryFromFreshModule(
|
|
@@ -147,7 +148,7 @@ export async function refreshLayoutChain(
|
|
|
147
148
|
// whether the export is currently a valid route (the chain entry was
|
|
148
149
|
// populated by the initial import and should be revisited on the next
|
|
149
150
|
// successful HMR cycle).
|
|
150
|
-
chainIdx
|
|
151
|
+
chainIdx += 1;
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
|
|
@@ -173,9 +174,9 @@ export function rebuildDevRoute(
|
|
|
173
174
|
): ResolvedRoute {
|
|
174
175
|
return {
|
|
175
176
|
...base,
|
|
177
|
+
mode: resolveMode(page, chain),
|
|
176
178
|
page,
|
|
177
179
|
routeChain: chain,
|
|
178
|
-
mode: resolveMode(page, chain),
|
|
179
180
|
tags: collectRouteTags(chain, page),
|
|
180
181
|
};
|
|
181
182
|
}
|
|
@@ -255,7 +256,7 @@ export async function handleDevRequest(
|
|
|
255
256
|
// delegating to renderSSR with an undefined page.
|
|
256
257
|
return new Response(
|
|
257
258
|
`<!doctype html><html><body><h1>Page load error</h1><p>Could not load ${route.path}. Check the server console for details.</p></body></html>`,
|
|
258
|
-
{
|
|
259
|
+
{ headers: { "Content-Type": "text/html; charset=utf-8" }, status: 500 }
|
|
259
260
|
);
|
|
260
261
|
}
|
|
261
262
|
|
|
@@ -271,15 +272,16 @@ export async function renderDevISRWithLoaderCache(
|
|
|
271
272
|
root: RootLayout,
|
|
272
273
|
searchRoutes?: SearchRouteMetadata[]
|
|
273
274
|
): Promise<Response> {
|
|
274
|
-
const
|
|
275
|
+
const resolvedPath = resolvePath(route.pattern, ctx.params ?? {});
|
|
276
|
+
const cacheKey = `${root.path}:${pathWithRequestSearch(resolvedPath, ctx.request.url)}`;
|
|
275
277
|
const cached = getDevISRLoaderCache(cacheKey);
|
|
276
278
|
|
|
277
279
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
278
280
|
const precomputed: LoaderResult = {
|
|
279
|
-
type: "data",
|
|
280
|
-
syncData: cached.loaderData,
|
|
281
281
|
deferredPromises: undefined,
|
|
282
282
|
headers: cached.headers,
|
|
283
|
+
syncData: cached.loaderData,
|
|
284
|
+
type: "data",
|
|
283
285
|
};
|
|
284
286
|
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
285
287
|
}
|
|
@@ -297,7 +299,7 @@ export async function renderDevISRWithLoaderCache(
|
|
|
297
299
|
};
|
|
298
300
|
setDevISRLoaderCache(cacheKey, entry);
|
|
299
301
|
autoInvalidateRegistry.registerLoaderTags(
|
|
300
|
-
|
|
302
|
+
pathWithRequestSearch(resolvedPath, ctx.request.url),
|
|
301
303
|
route.tags
|
|
302
304
|
);
|
|
303
305
|
}
|
|
@@ -322,10 +324,10 @@ export async function renderDevSSGWithLoaderCache(
|
|
|
322
324
|
|
|
323
325
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
324
326
|
const precomputed: LoaderResult = {
|
|
325
|
-
type: "data",
|
|
326
|
-
syncData: cached.loaderData,
|
|
327
327
|
deferredPromises: undefined,
|
|
328
328
|
headers: cached.headers,
|
|
329
|
+
syncData: cached.loaderData,
|
|
330
|
+
type: "data",
|
|
329
331
|
};
|
|
330
332
|
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
331
333
|
}
|
|
@@ -19,10 +19,10 @@ export {
|
|
|
19
19
|
resolveMode,
|
|
20
20
|
} from "./patterns.ts";
|
|
21
21
|
export { createDataEndpoint, createRoutePlugin } from "./plugin.ts";
|
|
22
|
+
export { mergeRouteSchemas } from "./schema-merge.ts";
|
|
22
23
|
export {
|
|
23
24
|
applySchemaDefaults,
|
|
24
25
|
createSearchRouteMetadata,
|
|
25
|
-
mergeRouteSchemas,
|
|
26
26
|
parseDataEndpointPath,
|
|
27
27
|
} from "./schemas.ts";
|
|
28
28
|
export type { ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from "node:path";
|
|
2
|
-
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
2
|
+
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
3
3
|
|
|
4
4
|
export function collectIntermediateLayoutDirs(pagePath: string, rootPath: string): string[] {
|
|
5
5
|
const pageDir = pagePath.slice(0, pagePath.lastIndexOf("/"));
|
|
@@ -17,11 +17,11 @@ export function collectIntermediateLayoutDirs(pagePath: string, rootPath: string
|
|
|
17
17
|
|
|
18
18
|
export function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr" {
|
|
19
19
|
const routeConfig = page._route;
|
|
20
|
-
const mode = routeConfig.mode ??
|
|
21
|
-
const revalidate = routeConfig.revalidate ??
|
|
20
|
+
const mode = routeConfig.mode ?? page.mode;
|
|
21
|
+
const revalidate = routeConfig.revalidate ?? page.revalidate;
|
|
22
22
|
|
|
23
23
|
if (mode) {
|
|
24
|
-
return mode
|
|
24
|
+
return mode;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const hasLoader = routeChain.some((r) => r.loader) || !!page.loader;
|
|
@@ -47,7 +47,7 @@ export function filePathToPattern(path: string): string {
|
|
|
47
47
|
const segments: string[] = [];
|
|
48
48
|
const lastIndex = parts.length - 1;
|
|
49
49
|
|
|
50
|
-
for (let idx = 0; idx < parts.length; idx
|
|
50
|
+
for (let idx = 0; idx < parts.length; idx += 1) {
|
|
51
51
|
const part = parts[idx];
|
|
52
52
|
if (part === undefined || part.length === 0) {
|
|
53
53
|
continue;
|
|
@@ -122,15 +122,15 @@ export function compareRouteSpecificity(a: string, b: string): number {
|
|
|
122
122
|
const aSegments = a.split("/").filter((segment) => segment.length > 0);
|
|
123
123
|
const bSegments = b.split("/").filter((segment) => segment.length > 0);
|
|
124
124
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
125
|
-
for (let i = 0; i < length; i
|
|
125
|
+
for (let i = 0; i < length; i += 1) {
|
|
126
126
|
const aSegment = aSegments[i];
|
|
127
127
|
const bSegment = bSegments[i];
|
|
128
128
|
// The pattern that still has a segment here constrains one more position.
|
|
129
129
|
if (aSegment === undefined) {
|
|
130
|
-
return -1;
|
|
130
|
+
return bSegment === "*" ? 1 : -1;
|
|
131
131
|
}
|
|
132
132
|
if (bSegment === undefined) {
|
|
133
|
-
return 1;
|
|
133
|
+
return aSegment === "*" ? -1 : 1;
|
|
134
134
|
}
|
|
135
135
|
const diff = segmentSpecificity(aSegment) - segmentSpecificity(bSegment);
|
|
136
136
|
if (diff !== 0) {
|
|
@@ -153,25 +153,26 @@ export function buildRouteRegex(pattern: string): { regex: RegExp; paramNames: s
|
|
|
153
153
|
let i = 0;
|
|
154
154
|
while (i < pattern.length) {
|
|
155
155
|
if (pattern[i] === ":") {
|
|
156
|
-
|
|
156
|
+
i += 1;
|
|
157
|
+
const start = i;
|
|
157
158
|
while (i < pattern.length && pattern[i] !== "/") {
|
|
158
|
-
i
|
|
159
|
+
i += 1;
|
|
159
160
|
}
|
|
160
161
|
paramNames.push(pattern.slice(start, i));
|
|
161
162
|
source += "([^/]+)";
|
|
162
163
|
} else if (pattern[i] === "*") {
|
|
163
164
|
paramNames.push("*");
|
|
164
165
|
source += "(.*)";
|
|
165
|
-
i
|
|
166
|
+
i += 1;
|
|
166
167
|
} else {
|
|
167
168
|
const ch = pattern[i];
|
|
168
169
|
if (ch !== undefined) {
|
|
169
170
|
source += escapeRegExpChar(ch);
|
|
170
171
|
}
|
|
171
|
-
i
|
|
172
|
+
i += 1;
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
|
-
return { regex: new RegExp(`^${source}$`)
|
|
175
|
+
return { paramNames, regex: new RegExp(`^${source}$`) };
|
|
175
176
|
}
|
|
176
177
|
|
|
177
178
|
export interface RoutePatternLike {
|
|
@@ -206,13 +207,13 @@ export function buildRouteMatcher<TRoute extends RoutePatternLike>(
|
|
|
206
207
|
continue;
|
|
207
208
|
}
|
|
208
209
|
const params: Record<string, string> = {};
|
|
209
|
-
for (let i = 0; i < candidate.paramNames.length; i
|
|
210
|
+
for (let i = 0; i < candidate.paramNames.length; i += 1) {
|
|
210
211
|
const name = candidate.paramNames[i];
|
|
211
212
|
if (name !== undefined) {
|
|
212
213
|
params[name] = match[i + 1] ?? "";
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
|
-
return { route: candidate.route
|
|
216
|
+
return { params, route: candidate.route };
|
|
216
217
|
}
|
|
217
218
|
return null;
|
|
218
219
|
};
|
|
@@ -1,35 +1,137 @@
|
|
|
1
1
|
import { type AnyElysia, type Context, Elysia, t } from "elysia";
|
|
2
2
|
import type { AnySchema } from "elysia/types";
|
|
3
|
-
import {
|
|
3
|
+
import { toCrossJSONAsync } from "seroval";
|
|
4
4
|
import { computeErrorDigest } from "../../shared/digest.ts";
|
|
5
|
+
import { containsRscSource, serializeRouteFrames } from "../../shared/route-frame.ts";
|
|
5
6
|
import type { SearchParamsInput, SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
6
|
-
import { autoInvalidateRegistry } from "../auto-invalidate/registry.ts";
|
|
7
7
|
import { useLogger } from "../context-logger.ts";
|
|
8
|
+
import {
|
|
9
|
+
currentInstrumentationRequest,
|
|
10
|
+
emitPayloadSerialized,
|
|
11
|
+
} from "../devtools/instrumentation.ts";
|
|
8
12
|
import { injectSyncRuntimeScript, resolvePath } from "../render/assemble.ts";
|
|
13
|
+
import { handleISR } from "../render/isr.ts";
|
|
9
14
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
renderSSR,
|
|
15
|
+
hasRequestLoader,
|
|
16
|
+
type LoaderResult,
|
|
13
17
|
runLoaders,
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
runPublicLoaders,
|
|
19
|
+
withRequestLoaderData,
|
|
20
|
+
} from "../render/loaders.ts";
|
|
21
|
+
import { renderPprRoute } from "../render/ppr-route.ts";
|
|
22
|
+
import { createDeferredRouteFrameStream } from "../render/route-frame-transport.ts";
|
|
16
23
|
import { extractTitle } from "../render/shell.ts";
|
|
24
|
+
import { prerenderSSG } from "../render/ssg.ts";
|
|
25
|
+
import { renderSSR } from "../render/ssr.ts";
|
|
17
26
|
import { IS_DEV } from "../runtime-env.ts";
|
|
18
27
|
import { handleDevRequest } from "./hmr.ts";
|
|
19
28
|
import { buildRouteMatcher } from "./patterns.ts";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
mergeRouteSchemas,
|
|
23
|
-
parseDataEndpointPath,
|
|
24
|
-
parseRouteQuery,
|
|
25
|
-
} from "./schemas.ts";
|
|
29
|
+
import { mergeRouteSchemas } from "./schema-merge.ts";
|
|
30
|
+
import { parseDataEndpointPath, parseRouteParams, parseRouteQuery } from "./schemas.ts";
|
|
26
31
|
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
27
32
|
|
|
33
|
+
interface DataRouteParamsInput {
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
type SyntheticDataContext = Omit<Context, "params" | "query"> & {
|
|
29
|
-
params:
|
|
38
|
+
params: DataRouteParamsInput;
|
|
30
39
|
query: SearchParamsInput;
|
|
31
40
|
};
|
|
32
41
|
|
|
42
|
+
function emitSerializedPayload(body: string, kind: "route-data" | "rsc", requestUrl: string): void {
|
|
43
|
+
if (!IS_DEV) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const request = currentInstrumentationRequest();
|
|
47
|
+
if (request === undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
emitPayloadSerialized({
|
|
51
|
+
bytes: new TextEncoder().encode(body).byteLength,
|
|
52
|
+
kind,
|
|
53
|
+
operationId: request.operationId,
|
|
54
|
+
path: new URL(requestUrl).pathname,
|
|
55
|
+
requestId: request.requestId,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function runDataEndpointLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult> {
|
|
60
|
+
if (route.mode !== "isr" && route.mode !== "ssg") {
|
|
61
|
+
return runLoaders(route, ctx);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await runPublicLoaders(route, ctx);
|
|
65
|
+
if (result.type !== "data" || !hasRequestLoader(route)) {
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
return withRequestLoaderData(route, ctx, result);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function createLoaderDataResponse(
|
|
72
|
+
result: LoaderResult,
|
|
73
|
+
route: ResolvedRoute,
|
|
74
|
+
requestUrl: string
|
|
75
|
+
): Promise<Response> {
|
|
76
|
+
if (result.type === "redirect") {
|
|
77
|
+
const redirectUrl = new URL(result.response.headers.get("location") ?? "/", requestUrl);
|
|
78
|
+
const serialized = await toCrossJSONAsync({
|
|
79
|
+
__furinRedirect: redirectUrl.pathname + redirectUrl.search,
|
|
80
|
+
});
|
|
81
|
+
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
82
|
+
headers: { "content-type": "application/x-ndjson" },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (result.type === "not-found") {
|
|
86
|
+
const serialized = await toCrossJSONAsync({
|
|
87
|
+
__furinNotFound: { data: result.error.data, message: result.error.message },
|
|
88
|
+
__furinStatus: 404,
|
|
89
|
+
});
|
|
90
|
+
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
91
|
+
headers: { "content-type": "application/x-ndjson" },
|
|
92
|
+
status: 200,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (result.type === "error") {
|
|
96
|
+
const serialized = await toCrossJSONAsync({
|
|
97
|
+
__furinError: {
|
|
98
|
+
digest: computeErrorDigest(result.error),
|
|
99
|
+
message: result.message,
|
|
100
|
+
status: result.status,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
104
|
+
headers: { "content-type": "application/x-ndjson" },
|
|
105
|
+
status: result.status,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const syncDataWithTitle = withResolvedTitle(route, result.syncData);
|
|
110
|
+
if (result.deferredPromises !== undefined) {
|
|
111
|
+
return new Response(
|
|
112
|
+
createDeferredRouteFrameStream(syncDataWithTitle, result.deferredPromises),
|
|
113
|
+
{
|
|
114
|
+
headers: {
|
|
115
|
+
...result.headers,
|
|
116
|
+
"content-type": "application/x-furin-route",
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const body = serializeRouteFrames(syncDataWithTitle, undefined);
|
|
122
|
+
emitSerializedPayload(
|
|
123
|
+
body,
|
|
124
|
+
containsRscSource(syncDataWithTitle) ? "rsc" : "route-data",
|
|
125
|
+
requestUrl
|
|
126
|
+
);
|
|
127
|
+
return new Response(body, {
|
|
128
|
+
headers: {
|
|
129
|
+
...result.headers,
|
|
130
|
+
"content-type": "application/x-furin-route",
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
33
135
|
/** @internal Handles a production SSG route — sets ETags, Cache-Control, and Cache-Tag. */
|
|
34
136
|
async function handleSSGRequest(
|
|
35
137
|
route: ResolvedRoute,
|
|
@@ -38,8 +140,8 @@ async function handleSSGRequest(
|
|
|
38
140
|
buildId: string,
|
|
39
141
|
searchRoutes: SearchRouteMetadata[] | undefined
|
|
40
142
|
): Promise<unknown> {
|
|
41
|
-
const origin = new URL(ctx.request.url)
|
|
42
|
-
const entry = await prerenderSSG(route, ctx.params, root, origin, undefined, searchRoutes);
|
|
143
|
+
const { origin } = new URL(ctx.request.url);
|
|
144
|
+
const entry = await prerenderSSG(route, ctx.params ?? {}, root, origin, undefined, searchRoutes);
|
|
43
145
|
|
|
44
146
|
// Loader issued a redirect — forward it directly to the client.
|
|
45
147
|
if (entry instanceof Response) {
|
|
@@ -106,6 +208,10 @@ export function createRoutePlugin(
|
|
|
106
208
|
return handleDevRequest(route, ctx, root, searchRoutes);
|
|
107
209
|
}
|
|
108
210
|
|
|
211
|
+
if ((route.mode === "ssg" || route.mode === "isr") && hasRequestLoader(route)) {
|
|
212
|
+
return renderPprRoute(route, ctx, root, resolvedBuildId, searchRoutes);
|
|
213
|
+
}
|
|
214
|
+
|
|
109
215
|
if (route.mode === "ssg") {
|
|
110
216
|
return handleSSGRequest(route, ctx, root, resolvedBuildId, searchRoutes);
|
|
111
217
|
}
|
|
@@ -124,13 +230,10 @@ export function createRoutePlugin(
|
|
|
124
230
|
/**
|
|
125
231
|
* Elysia plugin that handles `GET /_furin/data?path=<logicalHref>`.
|
|
126
232
|
*
|
|
127
|
-
* Returns
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* serialising, so the client receives all data resolved in one round-trip.
|
|
132
|
-
* SPA navigation calls this endpoint via `parseDeferredNdjson` in
|
|
133
|
-
* `router-provider.tsx`.
|
|
233
|
+
* Returns route-frame loader data for successful routes. Deferred routes stream
|
|
234
|
+
* the initial sync frame first, then append one frame batch per settled Promise.
|
|
235
|
+
* SPA navigation calls this endpoint via `parseDeferredNdjson`, which supports
|
|
236
|
+
* both route frames and legacy NDJSON sentinels.
|
|
134
237
|
*
|
|
135
238
|
* Special fields emitted alongside data:
|
|
136
239
|
* - `__furinStatus: 404` — when the loader called `notFound()`
|
|
@@ -180,21 +283,25 @@ export function createDataEndpoint(routes: ResolvedRoute[]): AnyElysia {
|
|
|
180
283
|
// Build the synthetic URL from the parsed `pathname + search` only —
|
|
181
284
|
// never from `rawPath` directly — so an attacker cannot smuggle a
|
|
182
285
|
// foreign origin into `syntheticRequest.url`.
|
|
183
|
-
|
|
286
|
+
// Forward the real request headers (cookies, auth) so loaders reading
|
|
287
|
+
// `request.headers` behave the same during SPA navigation as in SSR.
|
|
288
|
+
const syntheticRequest = new Request(new URL(pathname + url.search, ctx.request.url), {
|
|
289
|
+
headers: ctx.request.headers,
|
|
290
|
+
});
|
|
184
291
|
const syntheticSet = { headers: {} as Record<string, string>, status: 200 as number };
|
|
185
292
|
const syntheticCtx: SyntheticDataContext = {
|
|
186
|
-
request: syntheticRequest,
|
|
187
|
-
params: matched.params,
|
|
188
|
-
query: Object.fromEntries(url.searchParams),
|
|
189
|
-
set: syntheticSet,
|
|
190
|
-
headers: ctx.headers,
|
|
191
293
|
cookie: ctx.cookie,
|
|
294
|
+
headers: ctx.headers,
|
|
295
|
+
params: matched.params,
|
|
192
296
|
path: pathname,
|
|
297
|
+
query: Object.fromEntries(url.searchParams),
|
|
193
298
|
// Loader-emitted redirects flow through `runLoaders` → `result.type
|
|
194
299
|
// === "redirect"` and are converted to NDJSON below. The Response we
|
|
195
300
|
// return here only has to be detectable by that pipeline.
|
|
196
301
|
redirect: (location: string, status?: number) =>
|
|
197
|
-
new Response(null, {
|
|
302
|
+
new Response(null, { headers: { location }, status: status ?? 302 }),
|
|
303
|
+
request: syntheticRequest,
|
|
304
|
+
set: syntheticSet,
|
|
198
305
|
// Synthetic `status` helper: numeric codes only. Callers that reach
|
|
199
306
|
// this endpoint never dispatch a string-keyed status; rejecting them
|
|
200
307
|
// is safer than coercing via `Number(code)` and silently producing
|
|
@@ -206,6 +313,13 @@ export function createDataEndpoint(routes: ResolvedRoute[]): AnyElysia {
|
|
|
206
313
|
// createRoutePlugin so loaders see identical typed/defaulted inputs.
|
|
207
314
|
const mergedParams = mergeRouteSchemas(matched.route.routeChain, "params");
|
|
208
315
|
const mergedQuery = mergeRouteSchemas(matched.route.routeChain, "query");
|
|
316
|
+
const parsedParams = await parseRouteParams(matched.params, mergedParams);
|
|
317
|
+
if (!parsedParams.ok) {
|
|
318
|
+
return Response.json(
|
|
319
|
+
{ errors: parsedParams.errors, message: "Invalid params", type: "validation" },
|
|
320
|
+
{ status: 422 }
|
|
321
|
+
);
|
|
322
|
+
}
|
|
209
323
|
const parsedQuery = await parseRouteQuery(url, mergedQuery);
|
|
210
324
|
if (!parsedQuery.ok) {
|
|
211
325
|
return Response.json(
|
|
@@ -213,100 +327,15 @@ export function createDataEndpoint(routes: ResolvedRoute[]): AnyElysia {
|
|
|
213
327
|
{ status: 422 }
|
|
214
328
|
);
|
|
215
329
|
}
|
|
216
|
-
syntheticCtx.params =
|
|
217
|
-
mergedParams as Record<string, unknown> | undefined,
|
|
218
|
-
syntheticCtx.params as Record<string, unknown>
|
|
219
|
-
) as Record<string, string>;
|
|
330
|
+
syntheticCtx.params = parsedParams.params;
|
|
220
331
|
syntheticCtx.query = parsedQuery.query as SearchParamsInput;
|
|
221
332
|
|
|
222
|
-
const result = await
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// afterHandle) can still find this URL by tag. Without this, a SPA-only
|
|
227
|
-
// navigation path (which never goes through the full-HTML render that
|
|
228
|
-
// also registers tags) would silently fall off the registry — the first
|
|
229
|
-
// mutation invalidates and unregisters via the cache `onDelete` hook,
|
|
230
|
-
// the next SPA fetch re-loads but does not re-register, and from then
|
|
231
|
-
// on `revalidateTag` finds no path to invalidate.
|
|
232
|
-
if (result.type === "data") {
|
|
233
|
-
autoInvalidateRegistry.registerLoaderTags(pathname, matched.route.tags);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (result.type === "redirect") {
|
|
237
|
-
// Encode the redirect target as a special field for the client to follow
|
|
238
|
-
const redirectUrl = new URL(
|
|
239
|
-
result.response.headers.get("location") ?? "/",
|
|
240
|
-
ctx.request.url
|
|
241
|
-
);
|
|
242
|
-
const serialized = await toCrossJSONAsync({
|
|
243
|
-
__furinRedirect: redirectUrl.pathname + redirectUrl.search,
|
|
244
|
-
});
|
|
245
|
-
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
246
|
-
headers: { "content-type": "application/x-ndjson" },
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (result.type === "not-found") {
|
|
251
|
-
const serialized = await toCrossJSONAsync({
|
|
252
|
-
__furinStatus: 404,
|
|
253
|
-
__furinNotFound: { message: result.error.message, data: result.error.data },
|
|
254
|
-
});
|
|
255
|
-
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
256
|
-
status: 200,
|
|
257
|
-
headers: { "content-type": "application/x-ndjson" },
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (result.type === "error") {
|
|
262
|
-
// Compute the digest server-side ONCE so:
|
|
263
|
-
// 1. The HTTP response body carries it (client error UI displays the
|
|
264
|
-
// same id the server logs).
|
|
265
|
-
// 2. The server-log line below uses the SAME digest a user would see
|
|
266
|
-
// on screen, enabling support correlation.
|
|
267
|
-
// Recomputing client-side from a synthetic message + stack would yield
|
|
268
|
-
// a different hash — see boundaries.tsx for the digest precedence.
|
|
269
|
-
const digest = computeErrorDigest(result.error);
|
|
270
|
-
const serialized = await toCrossJSONAsync({
|
|
271
|
-
__furinError: {
|
|
272
|
-
digest,
|
|
273
|
-
message: result.message,
|
|
274
|
-
status: result.status,
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
278
|
-
status: result.status,
|
|
279
|
-
headers: { "content-type": "application/x-ndjson" },
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Resolve the page title server-side: head() never runs in the browser,
|
|
284
|
-
// so SPA navigation depends on the endpoint shipping it as __furinTitle.
|
|
285
|
-
const syncDataWithTitle = withResolvedTitle(matched.route, result.syncData);
|
|
286
|
-
|
|
287
|
-
if (result.deferredPromises) {
|
|
288
|
-
return new Response(
|
|
289
|
-
createDeferredNdjsonStream(syncDataWithTitle, result.deferredPromises),
|
|
290
|
-
{
|
|
291
|
-
// Loader headers first so custom headers survive; the NDJSON
|
|
292
|
-
// content-type is framework-owned and must win — a loader cannot be
|
|
293
|
-
// allowed to mislabel the data-endpoint payload.
|
|
294
|
-
headers: {
|
|
295
|
-
...result.headers,
|
|
296
|
-
"content-type": "application/x-ndjson",
|
|
297
|
-
},
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
}
|
|
333
|
+
const result = await runDataEndpointLoaders(
|
|
334
|
+
matched.route,
|
|
335
|
+
syntheticCtx as unknown as Context
|
|
336
|
+
);
|
|
301
337
|
|
|
302
|
-
|
|
303
|
-
const serialized = await toCrossJSONAsync(syncDataWithTitle);
|
|
304
|
-
return new Response(`${JSON.stringify(serialized)}\n`, {
|
|
305
|
-
headers: {
|
|
306
|
-
...result.headers,
|
|
307
|
-
"content-type": "application/x-ndjson",
|
|
308
|
-
},
|
|
309
|
-
});
|
|
338
|
+
return createLoaderDataResponse(result, matched.route, syntheticRequest.url);
|
|
310
339
|
},
|
|
311
340
|
{
|
|
312
341
|
query: t.Object({ path: t.Optional(t.String()) }),
|
|
@@ -331,7 +360,7 @@ function withResolvedTitle(
|
|
|
331
360
|
route: ResolvedRoute,
|
|
332
361
|
syncData: Record<string, unknown>
|
|
333
362
|
): Record<string, unknown> {
|
|
334
|
-
const head = route.page
|
|
363
|
+
const { head } = route.page;
|
|
335
364
|
if (!head) {
|
|
336
365
|
return syncData;
|
|
337
366
|
}
|
|
@@ -346,39 +375,3 @@ function withResolvedTitle(
|
|
|
346
375
|
}
|
|
347
376
|
return { ...syncData, __furinTitle: title };
|
|
348
377
|
}
|
|
349
|
-
|
|
350
|
-
function createDeferredNdjsonStream(
|
|
351
|
-
syncData: Record<string, unknown>,
|
|
352
|
-
deferredPromises: Record<string, Promise<unknown>>
|
|
353
|
-
): ReadableStream<Uint8Array> {
|
|
354
|
-
const enc = new TextEncoder();
|
|
355
|
-
const entries = Object.entries(deferredPromises);
|
|
356
|
-
|
|
357
|
-
return new ReadableStream<Uint8Array>({
|
|
358
|
-
async start(controller) {
|
|
359
|
-
const initial = toCrossJSON({
|
|
360
|
-
...syncData,
|
|
361
|
-
__furinDeferredKeys: entries.map(([key]) => key),
|
|
362
|
-
});
|
|
363
|
-
controller.enqueue(enc.encode(`${JSON.stringify(initial)}\n`));
|
|
364
|
-
|
|
365
|
-
await Promise.all(
|
|
366
|
-
entries.map(async ([key, promise]) => {
|
|
367
|
-
try {
|
|
368
|
-
const value = await promise;
|
|
369
|
-
controller.enqueue(
|
|
370
|
-
enc.encode(
|
|
371
|
-
`${JSON.stringify({ key, action: "resolve", value: toCrossJSON(value) })}\n`
|
|
372
|
-
)
|
|
373
|
-
);
|
|
374
|
-
} catch (err) {
|
|
375
|
-
const normalized = await serializeDeferredRejection(err);
|
|
376
|
-
const value = toCrossJSON(normalized);
|
|
377
|
-
controller.enqueue(enc.encode(`${JSON.stringify({ key, action: "reject", value })}\n`));
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
);
|
|
381
|
-
controller.close();
|
|
382
|
-
},
|
|
383
|
-
});
|
|
384
|
-
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { t } from "elysia";
|
|
2
|
+
import type { AnySchema } from "elysia/types";
|
|
3
|
+
import type { RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
4
|
+
|
|
5
|
+
interface SchemaObject {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
10
|
+
const TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
|
|
11
|
+
|
|
12
|
+
function isTypeBoxObjectSchema(schema: unknown): schema is SchemaObject {
|
|
13
|
+
return (
|
|
14
|
+
schema !== null &&
|
|
15
|
+
typeof schema === "object" &&
|
|
16
|
+
(schema as SchemaObject & { [key: symbol]: unknown })[TYPEBOX_KIND] === "Object"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function mergeRouteSchemas(
|
|
21
|
+
routeChain: RuntimeRoute[],
|
|
22
|
+
key: "params" | "query"
|
|
23
|
+
): AnySchema | undefined {
|
|
24
|
+
const schemas = routeChain.flatMap((route) => (route[key] ? [route[key] as SchemaObject] : []));
|
|
25
|
+
|
|
26
|
+
if (schemas.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (schemas.length === 1) {
|
|
30
|
+
return schemas[0] as AnySchema;
|
|
31
|
+
}
|
|
32
|
+
if (schemas.some((schema) => !isTypeBoxObjectSchema(schema))) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`[furin] Merging ${key} schemas across the route chain requires TypeBox in V1. Use TypeBox for parent/child ${key}, or define ${key} only on leaf routes.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const properties = Object.assign(
|
|
39
|
+
{},
|
|
40
|
+
...schemas.map((schema) => schema.properties as SchemaObject)
|
|
41
|
+
);
|
|
42
|
+
const options = Object.assign(
|
|
43
|
+
{},
|
|
44
|
+
...schemas.map((schema) =>
|
|
45
|
+
Object.fromEntries(
|
|
46
|
+
Object.entries(schema).filter(([name]) => !TOBJECT_STRUCTURAL_KEYS.has(name))
|
|
47
|
+
)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return t.Object(properties, options) as AnySchema;
|
|
52
|
+
}
|