@teyik0/furin 0.2.0-alpha.1 → 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.
- package/package.json +8 -3
- package/src/adapter/static.ts +23 -6
- package/src/build/client.ts +5 -2
- package/src/build/hydrate.ts +7 -1
- package/src/build/route-types.ts +37 -7
- package/src/build/shared.ts +1 -0
- package/src/build/ssg-cache.ts +3 -2
- package/src/client/link.tsx +13 -4
- package/src/client/router/context.ts +2 -0
- package/src/client/router/index.ts +9 -0
- package/src/client/router/link-utils.ts +5 -8
- package/src/client/router/navigation.ts +61 -0
- package/src/client/router/provider.tsx +59 -23
- package/src/client/router/search/index.ts +99 -0
- package/src/client/router/search-store.ts +86 -0
- package/src/client/router/types.ts +12 -4
- package/src/furin.ts +11 -4
- package/src/server/render/isr.ts +29 -7
- package/src/server/render/not-found.ts +2 -0
- package/src/server/render/ssg.ts +15 -4
- package/src/server/render/ssr.ts +47 -9
- package/src/server/router/hmr.ts +14 -10
- package/src/server/router/index.ts +1 -2
- package/src/server/router/patterns.ts +5 -0
- package/src/server/router/plugin.ts +28 -45
- package/src/server/router/schemas.ts +172 -57
- package/src/shared/search-params.ts +182 -0
- package/dist/adapter/bun.d.ts +0 -3
- package/dist/adapter/static.d.ts +0 -3
- package/dist/build/client.d.ts +0 -25
- package/dist/build/compile-entry.d.ts +0 -9
- package/dist/build/compile-entry.ts +0 -109
- package/dist/build/entry-template.d.ts +0 -38
- package/dist/build/entry-template.ts +0 -156
- package/dist/build/hydrate.d.ts +0 -24
- package/dist/build/index.d.ts +0 -8
- package/dist/build/index.js +0 -7069
- package/dist/build/route-types.d.ts +0 -21
- package/dist/build/scan-server.d.ts +0 -8
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -36
- package/dist/build/shared.d.ts +0 -11
- package/dist/build/ssg-cache.d.ts +0 -4
- package/dist/build/types.d.ts +0 -80
- package/dist/cli/config.d.ts +0 -9
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -7082
- package/dist/client/boundaries.d.ts +0 -117
- package/dist/client/default-screens.d.ts +0 -17
- package/dist/client/link.d.ts +0 -22
- package/dist/client/link.js +0 -3450
- package/dist/client/router/boundary-tree.d.ts +0 -26
- package/dist/client/router/context.d.ts +0 -8
- package/dist/client/router/history.d.ts +0 -9
- package/dist/client/router/index.d.ts +0 -7
- package/dist/client/router/link-utils.d.ts +0 -51
- package/dist/client/router/provider.d.ts +0 -4
- package/dist/client/router/spa-response.d.ts +0 -58
- package/dist/client/router/types.d.ts +0 -279
- package/dist/client/server-error.d.ts +0 -12
- package/dist/client.d.ts +0 -242
- package/dist/client.js +0 -96
- package/dist/config.d.ts +0 -57
- package/dist/config.js +0 -29
- package/dist/env.d.ts +0 -50
- package/dist/furin.d.ts +0 -69
- package/dist/furin.js +0 -7373
- package/dist/plugin/index.d.ts +0 -20
- package/dist/plugin/index.js +0 -1500
- package/dist/plugin/transform-client.d.ts +0 -10
- package/dist/server/auto-invalidate/index.d.ts +0 -4
- package/dist/server/auto-invalidate/plugin.d.ts +0 -38
- package/dist/server/auto-invalidate/registry.d.ts +0 -9
- package/dist/server/auto-invalidate/runtime.d.ts +0 -9
- package/dist/server/auto-invalidate/types.d.ts +0 -12
- package/dist/server/cache/dev-loader.d.ts +0 -28
- package/dist/server/cache/index.d.ts +0 -10
- package/dist/server/cache/invalidation.d.ts +0 -12
- package/dist/server/cache/isr-ssg.d.ts +0 -26
- package/dist/server/cache/isr.d.ts +0 -6
- package/dist/server/cache/registry.d.ts +0 -5
- package/dist/server/cache/route-cache.d.ts +0 -26
- package/dist/server/cache/ssg.d.ts +0 -5
- package/dist/server/context-logger.d.ts +0 -28
- package/dist/server/dev-inspector.d.ts +0 -89
- package/dist/server/dev-page-plugin.d.ts +0 -109
- package/dist/server/internal.d.ts +0 -35
- package/dist/server/internal.js +0 -17
- package/dist/server/lang-detect.d.ts +0 -5
- package/dist/server/render/assemble.d.ts +0 -47
- package/dist/server/render/element.d.ts +0 -24
- package/dist/server/render/index.d.ts +0 -7
- package/dist/server/render/index.ts +0 -22
- package/dist/server/render/isr.d.ts +0 -3
- package/dist/server/render/loaders.d.ts +0 -64
- package/dist/server/render/not-found.d.ts +0 -6
- package/dist/server/render/shell.d.ts +0 -39
- package/dist/server/render/shell.ts +0 -202
- package/dist/server/render/ssg.d.ts +0 -8
- package/dist/server/render/ssr.d.ts +0 -107
- package/dist/server/render/template.d.ts +0 -6
- package/dist/server/router/discovery.d.ts +0 -16
- package/dist/server/router/hmr.d.ts +0 -64
- package/dist/server/router/index.d.ts +0 -6
- package/dist/server/router/index.js +0 -28
- package/dist/server/router/index.ts +0 -29
- package/dist/server/router/patterns.d.ts +0 -40
- package/dist/server/router/plugin.d.ts +0 -20
- package/dist/server/router/schemas.d.ts +0 -51
- package/dist/server/router/types.d.ts +0 -60
- package/dist/server/runtime-env.d.ts +0 -3
- package/dist/server/runtime-env.js +0 -10
- package/dist/shared/await.d.ts +0 -67
- package/dist/shared/deferred-ndjson.d.ts +0 -32
- package/dist/shared/digest.d.ts +0 -16
- package/dist/shared/error.d.ts +0 -37
- package/dist/shared/not-found.d.ts +0 -19
- package/dist/shared/utils/ast-walk.d.ts +0 -18
- package/dist/shared/utils/index.d.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "teyik0",
|
|
@@ -76,6 +76,11 @@
|
|
|
76
76
|
"bun": "./src/client/link.tsx",
|
|
77
77
|
"import": "./dist/client/link.js"
|
|
78
78
|
},
|
|
79
|
+
"./search": {
|
|
80
|
+
"types": "./dist/client/router/search/index.d.ts",
|
|
81
|
+
"bun": "./src/client/router/search/index.ts",
|
|
82
|
+
"import": "./dist/client/router/search/index.js"
|
|
83
|
+
},
|
|
79
84
|
"./env": {
|
|
80
85
|
"types": "./dist/env.d.ts",
|
|
81
86
|
"bun": "./src/env.d.ts"
|
|
@@ -92,7 +97,7 @@
|
|
|
92
97
|
"@elysiajs/static": "^1.4.10",
|
|
93
98
|
"magic-string": "^0.30.21",
|
|
94
99
|
"seroval": "^1.5.4",
|
|
95
|
-
"yuku-parser": "^0.5.
|
|
100
|
+
"yuku-parser": "^0.5.37"
|
|
96
101
|
},
|
|
97
102
|
"devDependencies": {
|
|
98
103
|
"@types/react": "^19.2.17",
|
|
@@ -101,7 +106,7 @@
|
|
|
101
106
|
},
|
|
102
107
|
"peerDependencies": {
|
|
103
108
|
"elysia": "^1.4.28",
|
|
104
|
-
"evlog": "^2.
|
|
109
|
+
"evlog": "^2.19.1",
|
|
105
110
|
"react": "^19.2.7",
|
|
106
111
|
"react-dom": "^19.2.7"
|
|
107
112
|
}
|
package/src/adapter/static.ts
CHANGED
|
@@ -8,7 +8,12 @@ import { resolvePath } from "../server/render/assemble.ts";
|
|
|
8
8
|
import { prerenderSSG } from "../server/render/index.ts";
|
|
9
9
|
import { generateProdIndexHtml } from "../server/render/shell.ts";
|
|
10
10
|
import { setProductionTemplateContent } from "../server/render/template.ts";
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
createSearchRouteMetadata,
|
|
13
|
+
type ResolvedRoute,
|
|
14
|
+
type RootLayout,
|
|
15
|
+
} from "../server/router/index.ts";
|
|
16
|
+
import type { SearchRouteMetadata } from "../shared/search-params.ts";
|
|
12
17
|
import { mapWithConcurrency } from "../shared/utils/index.ts";
|
|
13
18
|
|
|
14
19
|
/** Maximum concurrent pre-render calls (mirrors warmSSGCache). */
|
|
@@ -55,14 +60,22 @@ async function prerenderAndWrite(
|
|
|
55
60
|
outDir: string,
|
|
56
61
|
renderedRoutes: string[],
|
|
57
62
|
skippedRoutes: string[],
|
|
58
|
-
basePath: string
|
|
63
|
+
basePath: string,
|
|
64
|
+
searchRoutes: SearchRouteMetadata[]
|
|
59
65
|
): Promise<void> {
|
|
60
66
|
const urlPath = resolvePath(route.pattern, params);
|
|
61
67
|
const htmlOutputFile = pathToOutputFile(urlPath, outDir, "index.html");
|
|
62
68
|
const dataOutputFile = pathToOutputFile(urlPath, outDir, "__furin_data.ndjson");
|
|
63
69
|
|
|
64
70
|
try {
|
|
65
|
-
const entry = await prerenderSSG(
|
|
71
|
+
const entry = await prerenderSSG(
|
|
72
|
+
route,
|
|
73
|
+
params,
|
|
74
|
+
root,
|
|
75
|
+
"http://localhost",
|
|
76
|
+
basePath,
|
|
77
|
+
searchRoutes
|
|
78
|
+
);
|
|
66
79
|
|
|
67
80
|
if (entry instanceof Response) {
|
|
68
81
|
console.warn(
|
|
@@ -138,7 +151,8 @@ async function buildTaskQueue(
|
|
|
138
151
|
outDir: string,
|
|
139
152
|
renderedRoutes: string[],
|
|
140
153
|
skippedRoutes: string[],
|
|
141
|
-
basePath: string
|
|
154
|
+
basePath: string,
|
|
155
|
+
searchRoutes: SearchRouteMetadata[]
|
|
142
156
|
): Promise<Array<() => Promise<void>>> {
|
|
143
157
|
const tasks: Array<() => Promise<void>> = [];
|
|
144
158
|
|
|
@@ -200,7 +214,8 @@ async function buildTaskQueue(
|
|
|
200
214
|
outDir,
|
|
201
215
|
renderedRoutes,
|
|
202
216
|
skippedRoutes,
|
|
203
|
-
basePath
|
|
217
|
+
basePath,
|
|
218
|
+
searchRoutes
|
|
204
219
|
)
|
|
205
220
|
);
|
|
206
221
|
}
|
|
@@ -294,6 +309,7 @@ export async function buildStaticTarget(
|
|
|
294
309
|
|
|
295
310
|
// ── 1. Validate SSR/ISR routes before doing any work ─────────────────────
|
|
296
311
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
312
|
+
const searchRoutes = createSearchRouteMetadata(ssgRoutes);
|
|
297
313
|
|
|
298
314
|
// ── 2. Clean & create output directories ─────────────────────────────────
|
|
299
315
|
rmSync(outDir, { force: true, recursive: true });
|
|
@@ -345,7 +361,8 @@ export async function buildStaticTarget(
|
|
|
345
361
|
outDir,
|
|
346
362
|
renderedRoutes,
|
|
347
363
|
skippedRoutes,
|
|
348
|
-
basePath
|
|
364
|
+
basePath,
|
|
365
|
+
searchRoutes
|
|
349
366
|
);
|
|
350
367
|
// Snapshot after queue-building: routes skipped due to missing staticParams() are
|
|
351
368
|
// already recorded; only routes added during task execution are prerender failures.
|
package/src/build/client.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { basename, join } from "node:path";
|
|
|
3
3
|
import { transformForClient } from "../plugin/transform-client";
|
|
4
4
|
import type { ResolvedRoute } from "../server/router/index.ts";
|
|
5
5
|
import { generateHydrateEntry } from "./hydrate";
|
|
6
|
-
import { CLIENT_MODULE_PATH, LINK_MODULE_PATH } from "./shared";
|
|
6
|
+
import { CLIENT_MODULE_PATH, LINK_MODULE_PATH, SEARCH_MODULE_PATH } from "./shared";
|
|
7
7
|
import type { BuildClientOptions, BunBuildAliasConfig } from "./types";
|
|
8
8
|
|
|
9
9
|
const TS_FILE_FILTER = /\.(tsx|ts)$/;
|
|
@@ -69,7 +69,9 @@ export async function buildClient(
|
|
|
69
69
|
.replaceAll(`"@teyik0/furin/client"`, JSON.stringify(CLIENT_MODULE_PATH))
|
|
70
70
|
.replaceAll(`'furin/client'`, JSON.stringify(CLIENT_MODULE_PATH))
|
|
71
71
|
.replaceAll(`"@teyik0/furin/link"`, JSON.stringify(LINK_MODULE_PATH))
|
|
72
|
-
.replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH))
|
|
72
|
+
.replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH))
|
|
73
|
+
.replaceAll(`"@teyik0/furin/search"`, JSON.stringify(SEARCH_MODULE_PATH))
|
|
74
|
+
.replaceAll(`'furin/search'`, JSON.stringify(SEARCH_MODULE_PATH));
|
|
73
75
|
|
|
74
76
|
return {
|
|
75
77
|
contents: transformed,
|
|
@@ -110,6 +112,7 @@ export async function buildClient(
|
|
|
110
112
|
alias: {
|
|
111
113
|
"@teyik0/furin/client": CLIENT_MODULE_PATH,
|
|
112
114
|
"@teyik0/furin/link": LINK_MODULE_PATH,
|
|
115
|
+
"@teyik0/furin/search": SEARCH_MODULE_PATH,
|
|
113
116
|
},
|
|
114
117
|
define: {
|
|
115
118
|
"process.env.NODE_ENV": JSON.stringify("production"),
|
package/src/build/hydrate.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { generateIndexHtml } from "../server/render/shell.ts";
|
|
4
|
+
import { mergeRouteSchemas } from "../server/router/index.ts";
|
|
4
5
|
import { buildRouteRegex } from "../server/router/patterns.ts";
|
|
5
6
|
import type { ResolvedRoute } from "../server/router/index.ts";
|
|
7
|
+
import { collectSearchDefaults } from "../shared/search-params.ts";
|
|
6
8
|
import { writeRouteTypes } from "./route-types";
|
|
7
9
|
import type { BuildClientOptions } from "./types";
|
|
8
10
|
|
|
@@ -44,6 +46,7 @@ export function generateHydrateEntry(
|
|
|
44
46
|
for (const route of routes) {
|
|
45
47
|
const resolvedPage = route.path.replace(/\\/g, "/");
|
|
46
48
|
const regexPattern = buildRouteRegex(route.pattern).regex.source;
|
|
49
|
+
const searchDefaults = collectSearchDefaults(mergeRouteSchemas(route.routeChain ?? [], "query"));
|
|
47
50
|
const boundaryIdents = new Map<string, string>();
|
|
48
51
|
|
|
49
52
|
// Emit one boundary literal per segment that actually carries a convention
|
|
@@ -77,8 +80,11 @@ export function generateHydrateEntry(
|
|
|
77
80
|
].join(", ")}]) => ({ default: __furin_page.default, segmentBoundaries: [${boundaryLiterals.join(", ")}] }))`
|
|
78
81
|
: `import("${resolvedPage}")`;
|
|
79
82
|
|
|
83
|
+
const searchDefaultsEntry = searchDefaults
|
|
84
|
+
? `, searchDefaults: ${JSON.stringify(searchDefaults)}`
|
|
85
|
+
: "";
|
|
80
86
|
routeEntries.push(
|
|
81
|
-
` { pattern: "${route.pattern}", regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody} }`
|
|
87
|
+
` { pattern: "${route.pattern}", regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody}${searchDefaultsEntry} }`
|
|
82
88
|
);
|
|
83
89
|
}
|
|
84
90
|
|
package/src/build/route-types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import type
|
|
3
|
+
import { mergeRouteSchemas, type ResolvedRoute } from "../server/router/index.ts";
|
|
4
4
|
|
|
5
5
|
/** @internal Exported for unit testing only. */
|
|
6
6
|
export function patternToTypeString(pattern: string): string {
|
|
@@ -17,6 +17,10 @@ export function patternToTypeString(pattern: string): string {
|
|
|
17
17
|
* @internal Exported for unit testing only.
|
|
18
18
|
*/
|
|
19
19
|
export function schemaToTypeString(schema: unknown): string {
|
|
20
|
+
return schemaToTypeStringWithDefaults(schema, true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function schemaToTypeStringWithDefaults(schema: unknown, defaultsAreRequired: boolean): string {
|
|
20
24
|
if (!schema || typeof schema !== "object") {
|
|
21
25
|
return "unknown";
|
|
22
26
|
}
|
|
@@ -24,7 +28,7 @@ export function schemaToTypeString(schema: unknown): string {
|
|
|
24
28
|
if (s.anyOf && Array.isArray(s.anyOf)) {
|
|
25
29
|
const parts: string[] = [];
|
|
26
30
|
for (const item of s.anyOf as unknown[]) {
|
|
27
|
-
const t =
|
|
31
|
+
const t = schemaToTypeStringWithDefaults(item, defaultsAreRequired);
|
|
28
32
|
if (t !== "null") parts.push(t);
|
|
29
33
|
}
|
|
30
34
|
return parts.join(" | ") || "unknown";
|
|
@@ -39,13 +43,21 @@ export function schemaToTypeString(schema: unknown): string {
|
|
|
39
43
|
return "boolean";
|
|
40
44
|
case "null":
|
|
41
45
|
return "null";
|
|
46
|
+
case "array": {
|
|
47
|
+
const inner = schemaToTypeStringWithDefaults(s.items, defaultsAreRequired);
|
|
48
|
+
return inner.includes("|") || inner.includes("&") ? `(${inner})[]` : `${inner}[]`;
|
|
49
|
+
}
|
|
42
50
|
case "object": {
|
|
43
51
|
if (!s.properties || typeof s.properties !== "object") {
|
|
44
52
|
return "Record<string, unknown>";
|
|
45
53
|
}
|
|
46
54
|
const required = new Set<string>(Array.isArray(s.required) ? (s.required as string[]) : []);
|
|
47
55
|
const props = Object.entries(s.properties as Record<string, unknown>)
|
|
48
|
-
.map(([k, v]) =>
|
|
56
|
+
.map(([k, v]) => {
|
|
57
|
+
const isPresent =
|
|
58
|
+
required.has(k) || (defaultsAreRequired && hasNonNullSchemaDefault(v));
|
|
59
|
+
return `${k}${isPresent ? "" : "?"}: ${schemaToTypeStringWithDefaults(v, defaultsAreRequired)}`;
|
|
60
|
+
})
|
|
49
61
|
.join("; ");
|
|
50
62
|
return `{ ${props} }`;
|
|
51
63
|
}
|
|
@@ -54,6 +66,22 @@ export function schemaToTypeString(schema: unknown): string {
|
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
|
|
69
|
+
/** @internal Exported for unit testing only. */
|
|
70
|
+
export function schemaToInputTypeString(schema: unknown): string {
|
|
71
|
+
return schemaToTypeStringWithDefaults(schema, false);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hasNonNullSchemaDefault(schema: unknown): boolean {
|
|
75
|
+
if (!schema || typeof schema !== "object") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const s = schema as Record<string, unknown>;
|
|
79
|
+
return (
|
|
80
|
+
"default" in s &&
|
|
81
|
+
s.default != null
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
57
85
|
function tagKeyToPropertyName(tag: string): string {
|
|
58
86
|
return /^[$A-Z_a-z][$\w]*$/.test(tag) ? tag : JSON.stringify(tag);
|
|
59
87
|
}
|
|
@@ -81,12 +109,14 @@ export function writeRouteTypes(routes: ResolvedRoute[], projectRoot: string): v
|
|
|
81
109
|
const entries = sortedRoutes.map((r) => {
|
|
82
110
|
const typeKey = patternToTypeString(r.pattern);
|
|
83
111
|
const isDynamic = typeKey.startsWith("`");
|
|
84
|
-
const querySchema = r.routeChain
|
|
112
|
+
const querySchema = mergeRouteSchemas(r.routeChain ?? [], "query");
|
|
85
113
|
const searchType = querySchema ? schemaToTypeString(querySchema) : "never";
|
|
114
|
+
const searchInputType = querySchema ? schemaToInputTypeString(querySchema) : "never";
|
|
86
115
|
return isDynamic
|
|
87
|
-
? ` [key: ${typeKey}]: { search?: ${searchType} }`
|
|
88
|
-
: ` ${typeKey}: { search?: ${searchType} }`;
|
|
116
|
+
? ` [key: ${typeKey}]: { search?: ${searchType}; searchInput?: ${searchInputType} }`
|
|
117
|
+
: ` ${typeKey}: { search?: ${searchType}; searchInput?: ${searchInputType} }`;
|
|
89
118
|
});
|
|
119
|
+
const routeManifestEntries = entries.join(";\n");
|
|
90
120
|
|
|
91
121
|
const sortedTags = [...new Set(routes.flatMap((route) => route.tags ?? []))].sort();
|
|
92
122
|
const tagBlock =
|
|
@@ -102,7 +132,7 @@ import "@teyik0/furin/link";
|
|
|
102
132
|
|
|
103
133
|
declare module "@teyik0/furin/link" {
|
|
104
134
|
interface RouteManifest {
|
|
105
|
-
${
|
|
135
|
+
${routeManifestEntries};
|
|
106
136
|
}
|
|
107
137
|
}${tagBlock}
|
|
108
138
|
`;
|
package/src/build/shared.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { BuildRouteManifestEntry, TargetBuildManifest } from "./types";
|
|
|
10
10
|
// exports. This is the Web-standard approach (Bun, Node 20.6+, browsers).
|
|
11
11
|
export const CLIENT_MODULE_PATH = new URL(import.meta.resolve("@teyik0/furin/client")).pathname;
|
|
12
12
|
export const LINK_MODULE_PATH = new URL(import.meta.resolve("@teyik0/furin/link")).pathname;
|
|
13
|
+
export const SEARCH_MODULE_PATH = new URL(import.meta.resolve("@teyik0/furin/search")).pathname;
|
|
13
14
|
|
|
14
15
|
export function ensureDir(path: string): void {
|
|
15
16
|
if (!existsSync(path)) {
|
package/src/build/ssg-cache.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
2
2
|
import { prerenderSSG } from "../server/render/index.ts";
|
|
3
|
-
import type
|
|
3
|
+
import { createSearchRouteMetadata, type ResolvedRoute, type RootLayout } from "../server/router/index.ts";
|
|
4
4
|
import { resolvePath } from "../server/render/assemble.ts";
|
|
5
5
|
|
|
6
6
|
export type SSGCacheSnapshot = Record<string, SsgCacheEntry>;
|
|
@@ -11,6 +11,7 @@ export async function buildSSGCacheSnapshot(
|
|
|
11
11
|
origin: string
|
|
12
12
|
): Promise<SSGCacheSnapshot> {
|
|
13
13
|
const snapshot: SSGCacheSnapshot = {};
|
|
14
|
+
const searchRoutes = createSearchRouteMetadata(routes);
|
|
14
15
|
|
|
15
16
|
for (const route of routes) {
|
|
16
17
|
if (route.mode !== "ssg" || !route.page.staticParams) {
|
|
@@ -19,7 +20,7 @@ export async function buildSSGCacheSnapshot(
|
|
|
19
20
|
|
|
20
21
|
const paramSets = await route.page.staticParams();
|
|
21
22
|
for (const params of paramSets) {
|
|
22
|
-
const entry = await prerenderSSG(route, params, root, origin, undefined);
|
|
23
|
+
const entry = await prerenderSSG(route, params, root, origin, undefined, searchRoutes);
|
|
23
24
|
if (entry instanceof Response) {
|
|
24
25
|
continue;
|
|
25
26
|
}
|
package/src/client/link.tsx
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3
|
+
import {
|
|
4
|
+
findSearchDefaultsForRouteTarget,
|
|
5
|
+
type SearchParamsInput,
|
|
6
|
+
} from "../shared/search-params.ts";
|
|
3
7
|
import {
|
|
4
8
|
buildHref,
|
|
5
9
|
CLIENT_FALLBACK_ROUTER,
|
|
@@ -39,15 +43,18 @@ function computeLinkView<To extends RouteTo>(
|
|
|
39
43
|
}: Pick<LinkProps<To>, "to" | "search" | "hash" | "children" | "activeProps" | "inactiveProps">,
|
|
40
44
|
router: RouterContextValue
|
|
41
45
|
): LinkView {
|
|
46
|
+
const searchDefaults = findSearchDefaultsForRouteTarget(to as string, router.searchRoutes);
|
|
42
47
|
const logicalHref = buildHref(
|
|
43
48
|
to as string,
|
|
44
|
-
search as
|
|
45
|
-
hash
|
|
49
|
+
search as SearchParamsInput | null | undefined,
|
|
50
|
+
hash,
|
|
51
|
+
searchDefaults
|
|
46
52
|
);
|
|
47
53
|
const logicalHrefWithoutHash = buildHref(
|
|
48
54
|
to as string,
|
|
49
|
-
search as
|
|
50
|
-
undefined
|
|
55
|
+
search as SearchParamsInput | null | undefined,
|
|
56
|
+
undefined,
|
|
57
|
+
searchDefaults
|
|
51
58
|
);
|
|
52
59
|
const isAbsolute =
|
|
53
60
|
logicalHref.startsWith("http://") ||
|
|
@@ -238,6 +245,8 @@ function LinkInteractive<To extends RouteTo>({
|
|
|
238
245
|
export const SSR_FALLBACK_ROUTER: RouterContextValue = {
|
|
239
246
|
basePath: "",
|
|
240
247
|
currentHref: "/",
|
|
248
|
+
search: {},
|
|
249
|
+
searchRoutes: [],
|
|
241
250
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
242
251
|
prefetch: (_href, _opts) => {
|
|
243
252
|
/* noop */
|
|
@@ -8,6 +8,8 @@ export const CLIENT_FALLBACK_ROUTER: RouterContextValue = {
|
|
|
8
8
|
// Use the same "/" as SSR_FALLBACK_ROUTER so SSR and client render the
|
|
9
9
|
// same active-state when no RouterProvider is present, avoiding hydration mismatches.
|
|
10
10
|
currentHref: "/",
|
|
11
|
+
search: {},
|
|
12
|
+
searchRoutes: [],
|
|
11
13
|
navigate: (href, _opts) => {
|
|
12
14
|
window.location.href = href;
|
|
13
15
|
return Promise.resolve();
|
|
@@ -20,7 +20,16 @@ export {
|
|
|
20
20
|
TRAILING_SLASHES_RE,
|
|
21
21
|
toLogical,
|
|
22
22
|
} from "./link-utils.ts";
|
|
23
|
+
export type { Navigate, NavigateInput } from "./navigation.ts";
|
|
24
|
+
export { useNavigate } from "./navigation.ts";
|
|
23
25
|
export { RouterProvider } from "./provider.tsx";
|
|
26
|
+
export type { SearchStore, SearchStoreSnapshot } from "./search-store.ts";
|
|
27
|
+
export {
|
|
28
|
+
createSearchStore,
|
|
29
|
+
FALLBACK_SEARCH_STORE,
|
|
30
|
+
SearchStoreContext,
|
|
31
|
+
searchSnapshotFromRouterContext,
|
|
32
|
+
} from "./search-store.ts";
|
|
24
33
|
export {
|
|
25
34
|
buildDataEndpoint,
|
|
26
35
|
buildNotFoundPageElement,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildSearchParams, type SearchParamsInput } from "../../shared/search-params.ts";
|
|
1
2
|
import type { CacheEntry } from "./types.ts";
|
|
2
3
|
|
|
3
4
|
const HASH_FRAGMENT_RE = /#.*$/;
|
|
@@ -12,17 +13,13 @@ export const TRAILING_SLASHES_RE = /\/+$/;
|
|
|
12
13
|
*/
|
|
13
14
|
export function buildHref(
|
|
14
15
|
to: string,
|
|
15
|
-
search:
|
|
16
|
-
hash: string | undefined
|
|
16
|
+
search: SearchParamsInput | null | undefined,
|
|
17
|
+
hash: string | undefined,
|
|
18
|
+
searchDefaults?: SearchParamsInput
|
|
17
19
|
): string {
|
|
18
20
|
let url = to;
|
|
19
21
|
if (search && Object.keys(search).length > 0) {
|
|
20
|
-
const params =
|
|
21
|
-
for (const [k, v] of Object.entries(search)) {
|
|
22
|
-
if (v != null) {
|
|
23
|
-
params.set(k, String(v));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
22
|
+
const params = buildSearchParams(search, searchDefaults);
|
|
26
23
|
const qs = params.toString();
|
|
27
24
|
if (qs) {
|
|
28
25
|
url += `?${qs}`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
findSearchDefaultsForRouteTarget,
|
|
4
|
+
type SearchParamsInput,
|
|
5
|
+
} from "../../shared/search-params.ts";
|
|
6
|
+
import { useRouter } from "./context.ts";
|
|
7
|
+
import { buildHref } from "./link-utils.ts";
|
|
8
|
+
import type { RouteSearch, RouteTo } from "./types.ts";
|
|
9
|
+
|
|
10
|
+
export interface NavigateInput<To extends RouteTo> {
|
|
11
|
+
hash?: string;
|
|
12
|
+
replace?: boolean;
|
|
13
|
+
resetScroll?: boolean;
|
|
14
|
+
search?: RouteSearch<To>;
|
|
15
|
+
to: To;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Navigate = <To extends RouteTo>(next: NavigateInput<To>) => Promise<void>;
|
|
19
|
+
type NavigateOptions = Parameters<ReturnType<typeof useRouter>["navigate"]>[1];
|
|
20
|
+
|
|
21
|
+
function isExternalAbsoluteHref(href: string): boolean {
|
|
22
|
+
if (href.startsWith("//")) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (!(href.startsWith("http://") || href.startsWith("https://"))) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (typeof window === "undefined") {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return new URL(href).origin !== window.location.origin;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useNavigate(): Navigate {
|
|
35
|
+
const router = useRouter();
|
|
36
|
+
|
|
37
|
+
return useCallback<Navigate>(
|
|
38
|
+
(next) => {
|
|
39
|
+
const searchDefaults = findSearchDefaultsForRouteTarget(
|
|
40
|
+
next.to as string,
|
|
41
|
+
router.searchRoutes
|
|
42
|
+
);
|
|
43
|
+
const href = buildHref(
|
|
44
|
+
next.to as string,
|
|
45
|
+
next.search as SearchParamsInput | null | undefined,
|
|
46
|
+
next.hash,
|
|
47
|
+
searchDefaults
|
|
48
|
+
);
|
|
49
|
+
if (isExternalAbsoluteHref(href) && typeof window !== "undefined") {
|
|
50
|
+
window.location.assign(href);
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
const opts: NavigateOptions =
|
|
54
|
+
next.replace === undefined && next.resetScroll === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: { replace: next.replace, resetScroll: next.resetScroll };
|
|
57
|
+
return router.navigate(href, opts);
|
|
58
|
+
},
|
|
59
|
+
[router]
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -2,6 +2,7 @@ import { log } from "evlog";
|
|
|
2
2
|
import type React from "react";
|
|
3
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { parseDeferredNdjson } from "../../shared/deferred-ndjson.ts";
|
|
5
|
+
import type { SearchParamsInput } from "../../shared/search-params.ts";
|
|
5
6
|
import { buildPageElement, buildRouterTree } from "./boundary-tree.tsx";
|
|
6
7
|
import {
|
|
7
8
|
generateHistoryKey,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
stripHashFromHref,
|
|
20
21
|
toLogical,
|
|
21
22
|
} from "./link-utils.ts";
|
|
23
|
+
import { createSearchStore, type SearchStore, SearchStoreContext } from "./search-store.ts";
|
|
22
24
|
import {
|
|
23
25
|
buildDataEndpoint,
|
|
24
26
|
buildNotFoundPageElement,
|
|
@@ -34,6 +36,8 @@ import type {
|
|
|
34
36
|
RouterState,
|
|
35
37
|
} from "./types.ts";
|
|
36
38
|
|
|
39
|
+
const EMPTY_SEARCH: SearchParamsInput = {};
|
|
40
|
+
|
|
37
41
|
export function setPrefetchCacheEntry(
|
|
38
42
|
cache: Map<string, CacheEntry>,
|
|
39
43
|
href: string,
|
|
@@ -113,6 +117,8 @@ export function RouterProvider({
|
|
|
113
117
|
* `__furin_data.ndjson` for static exports.
|
|
114
118
|
*/
|
|
115
119
|
const staticModeRef = useRef<boolean>(detectStaticMode());
|
|
120
|
+
const resolvedSearch = (state.data.query as SearchParamsInput | undefined) ?? EMPTY_SEARCH;
|
|
121
|
+
const searchStoreRef = useRef<SearchStore | null>(null);
|
|
116
122
|
|
|
117
123
|
/**
|
|
118
124
|
* Depth-0 boundary (pagesDir root level) for the "no client route matched" 404
|
|
@@ -458,6 +464,30 @@ export function RouterProvider({
|
|
|
458
464
|
[basePath, fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]
|
|
459
465
|
);
|
|
460
466
|
|
|
467
|
+
if (searchStoreRef.current === null) {
|
|
468
|
+
searchStoreRef.current = createSearchStore({
|
|
469
|
+
currentHref,
|
|
470
|
+
navigate,
|
|
471
|
+
search: resolvedSearch,
|
|
472
|
+
searchRoutes: routes,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
const searchStore = searchStoreRef.current;
|
|
476
|
+
const searchSnapshot = useMemo(
|
|
477
|
+
() => ({
|
|
478
|
+
currentHref,
|
|
479
|
+
navigate,
|
|
480
|
+
search: resolvedSearch,
|
|
481
|
+
searchRoutes: routes,
|
|
482
|
+
}),
|
|
483
|
+
[currentHref, navigate, resolvedSearch, routes]
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
useLayoutEffect(() => {
|
|
487
|
+
searchStore.setSnapshot(searchSnapshot);
|
|
488
|
+
searchStore.flush();
|
|
489
|
+
}, [searchStore, searchSnapshot]);
|
|
490
|
+
|
|
461
491
|
const refresh = useCallback(
|
|
462
492
|
async (opts: { resetScroll?: boolean } | undefined) => {
|
|
463
493
|
const logicalPath = toLogical(window.location.pathname, basePath);
|
|
@@ -696,28 +726,34 @@ export function RouterProvider({
|
|
|
696
726
|
);
|
|
697
727
|
}
|
|
698
728
|
|
|
699
|
-
return
|
|
700
|
-
{
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
729
|
+
return (
|
|
730
|
+
<SearchStoreContext.Provider value={searchStore}>
|
|
731
|
+
{buildRouterTree(
|
|
732
|
+
{
|
|
733
|
+
basePath,
|
|
734
|
+
currentHref,
|
|
735
|
+
search: resolvedSearch,
|
|
736
|
+
searchRoutes: routes,
|
|
737
|
+
navigate,
|
|
738
|
+
prefetch,
|
|
739
|
+
refresh,
|
|
740
|
+
invalidatePrefetch,
|
|
741
|
+
isNavigating,
|
|
742
|
+
defaultPreload,
|
|
743
|
+
defaultPreloadDelay,
|
|
744
|
+
defaultPreloadStaleTime,
|
|
745
|
+
},
|
|
746
|
+
pageElement,
|
|
747
|
+
{
|
|
748
|
+
digest: initialDigest,
|
|
749
|
+
onReset: () => {
|
|
750
|
+
refresh(undefined).catch((err: unknown) => {
|
|
751
|
+
log.error({ action: "boundary_reset_failed", error: String(err) });
|
|
752
|
+
});
|
|
753
|
+
},
|
|
754
|
+
resetKey: currentHref,
|
|
755
|
+
}
|
|
756
|
+
)}
|
|
757
|
+
</SearchStoreContext.Provider>
|
|
722
758
|
);
|
|
723
759
|
}
|