@reckona/mreact-router 0.0.160 → 0.0.161
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/actions.d.ts +6 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/adapters/aws-lambda.d.ts +29 -0
- package/dist/adapters/aws-lambda.d.ts.map +1 -1
- package/dist/adapters/aws-lambda.js.map +1 -1
- package/dist/adapters/cloudflare.d.ts +78 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/edge.d.ts +6 -0
- package/dist/adapters/edge.d.ts.map +1 -1
- package/dist/adapters/edge.js.map +1 -1
- package/dist/adapters/node.d.ts +7 -0
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js.map +1 -1
- package/dist/adapters/static.d.ts +6 -0
- package/dist/adapters/static.d.ts.map +1 -1
- package/dist/adapters/static.js.map +1 -1
- package/dist/app-router-globals.d.ts +6 -0
- package/dist/app-router-globals.d.ts.map +1 -1
- package/dist/app-router-globals.js.map +1 -1
- package/dist/assets.d.ts +18 -0
- package/dist/assets.d.ts.map +1 -1
- package/dist/assets.js +6 -0
- package/dist/assets.js.map +1 -1
- package/dist/build.d.ts +30 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +4 -0
- package/dist/build.js.map +1 -1
- package/dist/cache-stats.d.ts +3 -0
- package/dist/cache-stats.d.ts.map +1 -1
- package/dist/cache-stats.js.map +1 -1
- package/dist/cache.d.ts +15 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/cli-options.d.ts.map +1 -1
- package/dist/cli-options.js +2 -0
- package/dist/cli-options.js.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +15 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/cookies.d.ts +3 -0
- package/dist/cookies.d.ts.map +1 -1
- package/dist/cookies.js.map +1 -1
- package/dist/csrf.d.ts +12 -0
- package/dist/csrf.d.ts.map +1 -1
- package/dist/csrf.js +12 -0
- package/dist/csrf.js.map +1 -1
- package/dist/deferred.d.ts +9 -0
- package/dist/deferred.d.ts.map +1 -1
- package/dist/deferred.js +6 -0
- package/dist/deferred.js.map +1 -1
- package/dist/dev-server.d.ts +3 -0
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js.map +1 -1
- package/dist/file-conventions.d.ts +3 -0
- package/dist/file-conventions.d.ts.map +1 -1
- package/dist/file-conventions.js.map +1 -1
- package/dist/i18n.d.ts +15 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +6 -0
- package/dist/i18n.js.map +1 -1
- package/dist/import-policy.d.ts +3 -0
- package/dist/import-policy.d.ts.map +1 -1
- package/dist/import-policy.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +34 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js.map +1 -1
- package/dist/logger.d.ts +33 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/multipart.d.ts +15 -0
- package/dist/multipart.d.ts.map +1 -1
- package/dist/multipart.js +3 -0
- package/dist/multipart.js.map +1 -1
- package/dist/native-escape.d.ts +3 -0
- package/dist/native-escape.d.ts.map +1 -1
- package/dist/native-escape.js +3 -0
- package/dist/native-escape.js.map +1 -1
- package/dist/navigation-state.d.ts +15 -0
- package/dist/navigation-state.d.ts.map +1 -1
- package/dist/navigation-state.js +6 -0
- package/dist/navigation-state.js.map +1 -1
- package/dist/navigation.d.ts +9 -0
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +6 -0
- package/dist/navigation.js.map +1 -1
- package/dist/prerender-store.d.ts +21 -0
- package/dist/prerender-store.d.ts.map +1 -1
- package/dist/prerender-store.js +9 -0
- package/dist/prerender-store.js.map +1 -1
- package/dist/render.d.ts +12 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +3 -0
- package/dist/render.js.map +1 -1
- package/dist/routes.d.ts +30 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +6 -0
- package/dist/routes.js.map +1 -1
- package/dist/runtime-cache.d.ts +4 -0
- package/dist/runtime-cache.d.ts.map +1 -1
- package/dist/runtime-cache.js +3 -0
- package/dist/runtime-cache.js.map +1 -1
- package/dist/runtime-state.d.ts +3 -0
- package/dist/runtime-state.d.ts.map +1 -1
- package/dist/runtime-state.js +3 -0
- package/dist/runtime-state.js.map +1 -1
- package/dist/serve.d.ts +24 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +6 -0
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +12 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js.map +1 -1
- package/dist/stream-list.d.ts +12 -0
- package/dist/stream-list.d.ts.map +1 -1
- package/dist/stream-list.js +3 -0
- package/dist/stream-list.js.map +1 -1
- package/dist/trace.d.ts +30 -0
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +6 -0
- package/dist/trace.js.map +1 -1
- package/dist/typed-routes.d.ts +33 -0
- package/dist/typed-routes.d.ts.map +1 -1
- package/dist/typed-routes.js.map +1 -1
- package/dist/types.d.ts +72 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/upgrade.d.ts +3 -0
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js.map +1 -1
- package/dist/vite.d.ts +21 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +15 -0
- package/dist/vite.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.ts +6 -0
- package/src/adapters/aws-lambda.ts +29 -0
- package/src/adapters/cloudflare.ts +78 -0
- package/src/adapters/edge.ts +6 -0
- package/src/adapters/node.ts +7 -0
- package/src/adapters/static.ts +6 -0
- package/src/app-router-globals.ts +6 -0
- package/src/assets.ts +18 -0
- package/src/build.ts +38 -0
- package/src/cache-stats.ts +3 -0
- package/src/cache.ts +15 -0
- package/src/cli-options.ts +2 -0
- package/src/cli.ts +1 -0
- package/src/config.ts +15 -0
- package/src/cookies.ts +3 -0
- package/src/csrf.ts +12 -0
- package/src/deferred.ts +9 -0
- package/src/dev-server.ts +3 -0
- package/src/file-conventions.ts +3 -0
- package/src/i18n.ts +15 -0
- package/src/import-policy.ts +3 -0
- package/src/index.ts +19 -0
- package/src/link.ts +34 -0
- package/src/logger.ts +33 -0
- package/src/multipart.ts +15 -0
- package/src/native-escape.ts +3 -0
- package/src/navigation-state.ts +15 -0
- package/src/navigation.ts +9 -0
- package/src/prerender-store.ts +21 -0
- package/src/render.ts +12 -0
- package/src/routes.ts +30 -0
- package/src/runtime-cache.ts +5 -0
- package/src/runtime-state.ts +3 -0
- package/src/serve.ts +24 -0
- package/src/session.ts +12 -0
- package/src/stream-list.ts +12 -0
- package/src/trace.ts +30 -0
- package/src/typed-routes.ts +33 -0
- package/src/types.ts +72 -0
- package/src/upgrade.ts +3 -0
- package/src/vite.ts +21 -0
package/src/adapters/edge.ts
CHANGED
|
@@ -8,8 +8,14 @@ import {
|
|
|
8
8
|
type AppRouterLogger,
|
|
9
9
|
} from "../logger.js";
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Handles one standard Web `Request` in an edge runtime.
|
|
13
|
+
*/
|
|
11
14
|
export type EdgeRequestHandler = (request: Request) => Response | Promise<Response>;
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Configures edge-runtime logging, rendering, and error handling.
|
|
18
|
+
*/
|
|
13
19
|
export interface EdgeRequestHandlerOptions {
|
|
14
20
|
logger?: AppRouterLogger | undefined;
|
|
15
21
|
onError?: ((error: unknown, request: Request) => Response | Promise<Response>) | undefined;
|
package/src/adapters/node.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import type { AppRouterResponseHook } from "../render.js";
|
|
16
16
|
import type { RouterInstrumentation } from "../trace.js";
|
|
17
17
|
|
|
18
|
+
/** Re-exports router instrumentation hooks for Node handlers. */
|
|
18
19
|
export type { RouterInstrumentation } from "../trace.js";
|
|
19
20
|
import {
|
|
20
21
|
renderBuiltAppRequest,
|
|
@@ -25,6 +26,9 @@ import {
|
|
|
25
26
|
type ResponseSinkStrategy,
|
|
26
27
|
} from "../serve.js";
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Configures a Node request handler for built app-router output.
|
|
31
|
+
*/
|
|
28
32
|
export interface NodeRequestHandlerOptions {
|
|
29
33
|
allowedHosts?: readonly string[] | undefined;
|
|
30
34
|
errorHandler?:
|
|
@@ -48,6 +52,9 @@ export interface NodeRequestHandlerOptions {
|
|
|
48
52
|
sinkStrategy?: ResponseSinkStrategy | undefined;
|
|
49
53
|
}
|
|
50
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Handles one Node HTTP request/response pair for built app-router output.
|
|
57
|
+
*/
|
|
51
58
|
export type NodeRequestHandler = (
|
|
52
59
|
incoming: IncomingMessage,
|
|
53
60
|
outgoing: ServerResponse,
|
package/src/adapters/static.ts
CHANGED
|
@@ -2,12 +2,18 @@ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, join, resolve, sep } from "node:path";
|
|
3
3
|
import type { BuiltPrerenderedRoute, BuiltServerManifest } from "../build.js";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Configures static export from a built app-router output directory.
|
|
7
|
+
*/
|
|
5
8
|
export interface StaticExportOptions {
|
|
6
9
|
exportDir: string;
|
|
7
10
|
outDir: string;
|
|
8
11
|
paths?: readonly string[] | undefined;
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Lists the routes written by a static app-router export.
|
|
16
|
+
*/
|
|
11
17
|
export interface StaticExportResult {
|
|
12
18
|
routes: string[];
|
|
13
19
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ReactCompatElement, ReactCompatNode } from "@reckona/mreact-compat";
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
|
+
/**
|
|
5
|
+
* Renders the fulfilled, rejected, or placeholder state of a deferred value.
|
|
6
|
+
*/
|
|
4
7
|
function Await<T>(props: {
|
|
5
8
|
children?: (value: Awaited<T>) => ReactCompatNode;
|
|
6
9
|
catch?: (error: Error) => ReactCompatNode;
|
|
@@ -9,6 +12,9 @@ declare global {
|
|
|
9
12
|
value: T | PromiseLike<T>;
|
|
10
13
|
}): ReactCompatElement;
|
|
11
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Renders a named layout slot with optional fallback children.
|
|
17
|
+
*/
|
|
12
18
|
function Slot(props?: {
|
|
13
19
|
children?: ReactCompatNode;
|
|
14
20
|
name?: string;
|
package/src/assets.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes the generated files associated with a client bundle manifest entry.
|
|
3
|
+
*/
|
|
1
4
|
export interface AssetManifestEntry {
|
|
2
5
|
assets?: readonly string[];
|
|
3
6
|
css?: readonly string[];
|
|
@@ -5,17 +8,29 @@ export interface AssetManifestEntry {
|
|
|
5
8
|
imports?: readonly string[];
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Maps app-router entry keys to generated client asset metadata.
|
|
13
|
+
*/
|
|
8
14
|
export type AssetManifest = Readonly<Record<string, AssetManifestEntry>>;
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Configures URL generation for asset helper functions.
|
|
18
|
+
*/
|
|
10
19
|
export interface AssetHelperOptions {
|
|
11
20
|
base?: string;
|
|
12
21
|
}
|
|
13
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Represents a preload or stylesheet link descriptor derived from an asset manifest.
|
|
25
|
+
*/
|
|
14
26
|
export interface AssetLinkDescriptor {
|
|
15
27
|
attrs: Record<string, string>;
|
|
16
28
|
tag: "link";
|
|
17
29
|
}
|
|
18
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a manifest entry key to its public asset URL.
|
|
33
|
+
*/
|
|
19
34
|
export function assetHref(
|
|
20
35
|
manifest: AssetManifest,
|
|
21
36
|
key: string,
|
|
@@ -24,6 +39,9 @@ export function assetHref(
|
|
|
24
39
|
return assetPath(manifestEntry(manifest, key).file, options.base);
|
|
25
40
|
}
|
|
26
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Builds unique preload and stylesheet link descriptors for one or more manifest entries.
|
|
44
|
+
*/
|
|
27
45
|
export function assetPreloadLinks(
|
|
28
46
|
manifest: AssetManifest,
|
|
29
47
|
keys: readonly string[] | string,
|
package/src/build.ts
CHANGED
|
@@ -113,6 +113,9 @@ const serverArtifactFilesystemConcurrency = 2;
|
|
|
113
113
|
type ServerTransformOutput = ReturnType<typeof transform>;
|
|
114
114
|
type ServerTransformCache = Map<string, Promise<ServerTransformOutput>>;
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Configures an app-router production build and its deployment targets.
|
|
118
|
+
*/
|
|
116
119
|
export interface BuildAppOptions extends AppRouterProjectOptions {
|
|
117
120
|
onBuildProgress?: ((event: BuildAppProgressEvent) => void) | undefined;
|
|
118
121
|
onBuildPhaseTiming?: ((timing: BuildAppPhaseTiming) => void) | undefined;
|
|
@@ -161,6 +164,9 @@ async function collectBuildMiddlewareIds(appDir: string): Promise<ReadonlySet<st
|
|
|
161
164
|
return ids;
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Names a high-level phase reported while building an app-router application.
|
|
169
|
+
*/
|
|
164
170
|
export type BuildAppPhase =
|
|
165
171
|
| "scan"
|
|
166
172
|
| "collectFiles"
|
|
@@ -179,11 +185,17 @@ export type BuildAppPhase =
|
|
|
179
185
|
| "writeManifests"
|
|
180
186
|
| "adapterArtifacts";
|
|
181
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Captures the elapsed time for a completed app-router build phase.
|
|
190
|
+
*/
|
|
182
191
|
export interface BuildAppPhaseTiming {
|
|
183
192
|
ms: number;
|
|
184
193
|
phase: BuildAppPhase;
|
|
185
194
|
}
|
|
186
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Reports build progress events emitted during app-router compilation and packaging.
|
|
198
|
+
*/
|
|
187
199
|
export type BuildAppProgressEvent =
|
|
188
200
|
| {
|
|
189
201
|
kind: "phase-start";
|
|
@@ -199,16 +211,25 @@ export type BuildAppProgressEvent =
|
|
|
199
211
|
kind: "routes-discovered";
|
|
200
212
|
};
|
|
201
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Contains the route graph produced by an app-router build.
|
|
216
|
+
*/
|
|
202
217
|
export interface BuildAppResult {
|
|
203
218
|
routes: AppRoute[];
|
|
204
219
|
}
|
|
205
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Describes the generated import policy artifact consumed by built request handlers.
|
|
223
|
+
*/
|
|
206
224
|
export interface BuiltImportPolicyArtifact {
|
|
207
225
|
byRoute: Record<string, string[]>;
|
|
208
226
|
runtimePackages: string[];
|
|
209
227
|
version: 1;
|
|
210
228
|
}
|
|
211
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Summarizes the files and entry point produced for an AWS Lambda artifact.
|
|
232
|
+
*/
|
|
212
233
|
export interface AwsLambdaArtifactManifest {
|
|
213
234
|
files: Array<{ bytes: number; path: string }>;
|
|
214
235
|
handler: string;
|
|
@@ -217,6 +238,9 @@ export interface AwsLambdaArtifactManifest {
|
|
|
217
238
|
version: 1;
|
|
218
239
|
}
|
|
219
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Summarizes the files and worker entry produced for a Cloudflare Pages artifact.
|
|
243
|
+
*/
|
|
220
244
|
export interface CloudflarePagesArtifactManifest {
|
|
221
245
|
files: Array<{ bytes: number; path: string }>;
|
|
222
246
|
runtime: "cloudflare-pages";
|
|
@@ -225,6 +249,9 @@ export interface CloudflarePagesArtifactManifest {
|
|
|
225
249
|
worker: "_worker.js";
|
|
226
250
|
}
|
|
227
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Configures packaging of a built app-router output directory for AWS Lambda.
|
|
254
|
+
*/
|
|
228
255
|
export interface PackageAwsLambdaArtifactOptions {
|
|
229
256
|
fromDir: string;
|
|
230
257
|
handlerEntry?: string | undefined;
|
|
@@ -232,6 +259,9 @@ export interface PackageAwsLambdaArtifactOptions {
|
|
|
232
259
|
skipRuntimeDependencyCheck?: boolean | undefined;
|
|
233
260
|
}
|
|
234
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Configures packaging of a built app-router output directory for Cloudflare Pages.
|
|
264
|
+
*/
|
|
235
265
|
export interface PackageCloudflarePagesArtifactOptions {
|
|
236
266
|
fromDir: string;
|
|
237
267
|
outDir: string;
|
|
@@ -1876,6 +1906,13 @@ async function prerenderStaticRoutes(options: {
|
|
|
1876
1906
|
route.css !== undefined && route.css.length > 0 ? [[route.path, route.css]] : [],
|
|
1877
1907
|
),
|
|
1878
1908
|
);
|
|
1909
|
+
const navigationScripts = new Map(
|
|
1910
|
+
options.clientRoutes.flatMap((route) =>
|
|
1911
|
+
route.navigation === true && route.navigationScript !== undefined
|
|
1912
|
+
? [[route.path, route.navigationScript]]
|
|
1913
|
+
: [],
|
|
1914
|
+
),
|
|
1915
|
+
);
|
|
1879
1916
|
const prerendered: Record<string, BuiltPrerenderedRoute> = {};
|
|
1880
1917
|
const importPolicy = {
|
|
1881
1918
|
allowedPackages: await readDeclaredProjectPackages(options.project.projectRoot),
|
|
@@ -1914,6 +1951,7 @@ async function prerenderStaticRoutes(options: {
|
|
|
1914
1951
|
clientStyles,
|
|
1915
1952
|
define: options.define,
|
|
1916
1953
|
importPolicy,
|
|
1954
|
+
navigationScripts,
|
|
1917
1955
|
request: new Request(`http://mreact.local${pathname}`),
|
|
1918
1956
|
serverModuleCacheVersion,
|
|
1919
1957
|
serverModules: serverModuleMap,
|
package/src/cache-stats.ts
CHANGED
package/src/cache.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Describes the cache lifetime assigned to a rendered route response.
|
|
5
|
+
*/
|
|
3
6
|
export interface RouteCachePolicy {
|
|
4
7
|
cacheControl: string;
|
|
5
8
|
revalidateSeconds: number;
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Configures cache-control directives for route response caching.
|
|
13
|
+
*/
|
|
8
14
|
export interface CacheControlOptions {
|
|
9
15
|
maxAge?: number | undefined;
|
|
10
16
|
sMaxAge?: number | undefined;
|
|
11
17
|
staleWhileRevalidate?: boolean | number | undefined;
|
|
12
18
|
}
|
|
13
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Stores a cached route response body and its expiration metadata.
|
|
22
|
+
*/
|
|
14
23
|
export interface AppRouterCacheEntry {
|
|
15
24
|
body: string;
|
|
16
25
|
cacheControl: string;
|
|
@@ -19,6 +28,9 @@ export interface AppRouterCacheEntry {
|
|
|
19
28
|
status: number;
|
|
20
29
|
}
|
|
21
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Defines the storage interface used by app-router route response caching.
|
|
33
|
+
*/
|
|
22
34
|
export interface AppRouterCache {
|
|
23
35
|
deleteByPath(path: string): void | Promise<void>;
|
|
24
36
|
get(
|
|
@@ -28,6 +40,9 @@ export interface AppRouterCache {
|
|
|
28
40
|
set(key: string, entry: AppRouterCacheEntry): void | Promise<void>;
|
|
29
41
|
}
|
|
30
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Configures the process-local in-memory route cache implementation.
|
|
45
|
+
*/
|
|
31
46
|
export interface MemoryRouteCacheOptions {
|
|
32
47
|
maxEntries?: number;
|
|
33
48
|
sweepIntervalMs?: number;
|
package/src/cli-options.ts
CHANGED
|
@@ -256,11 +256,13 @@ export function formatCliHelp(command?: string | undefined): string {
|
|
|
256
256
|
"Start the mreact app router development server.",
|
|
257
257
|
"",
|
|
258
258
|
"Options:",
|
|
259
|
+
" --host <host> Bind address. Default: 127.0.0.1. Use 0.0.0.0 for LAN or device testing.",
|
|
259
260
|
" --port <port> TCP port. Overrides PORT and vite.config.ts server.port.",
|
|
260
261
|
" --log=requests Print request summaries.",
|
|
261
262
|
" -h, --help Show this help message.",
|
|
262
263
|
"",
|
|
263
264
|
"Environment:",
|
|
265
|
+
" HOST Bind address when --host is not set.",
|
|
264
266
|
" PORT TCP port when --port is not set.",
|
|
265
267
|
].join("\n");
|
|
266
268
|
}
|
package/src/cli.ts
CHANGED
|
@@ -119,6 +119,7 @@ if (parsed !== undefined) {
|
|
|
119
119
|
};
|
|
120
120
|
const server = await startDevServer({
|
|
121
121
|
...loaded.project,
|
|
122
|
+
hostname: resolveCliHost(parsed.host, process.env),
|
|
122
123
|
logger,
|
|
123
124
|
port: resolveCliDevPort(parsed.port, process.env, loaded.serverPort),
|
|
124
125
|
viteConfig: loaded.viteConfig,
|
package/src/config.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Selects the deployment runtime artifacts emitted by an app-router build.
|
|
5
|
+
*/
|
|
3
6
|
export type AppRouterBuildTarget = "node" | "cloudflare" | "aws-lambda";
|
|
7
|
+
/**
|
|
8
|
+
* Names a browser console method that can be stripped from client bundles.
|
|
9
|
+
*/
|
|
4
10
|
export type AppRouterClientConsoleMethod = "debug" | "error" | "info" | "log" | "trace" | "warn";
|
|
11
|
+
/**
|
|
12
|
+
* Controls how client bundle source maps are generated.
|
|
13
|
+
*/
|
|
5
14
|
export type AppRouterClientSourceMapMode = "none" | "hidden" | "linked";
|
|
15
|
+
/**
|
|
16
|
+
* Configures client source map output with a boolean shortcut or explicit mode.
|
|
17
|
+
*/
|
|
6
18
|
export type AppRouterClientSourceMapOption = boolean | AppRouterClientSourceMapMode;
|
|
7
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Configures production-only app-router build behavior.
|
|
22
|
+
*/
|
|
8
23
|
export interface AppRouterProductionOptions {
|
|
9
24
|
dropClientConsole?: boolean | readonly AppRouterClientConsoleMethod[] | undefined;
|
|
10
25
|
}
|
package/src/cookies.ts
CHANGED
package/src/csrf.ts
CHANGED
|
@@ -2,6 +2,9 @@ const csrfCookieNameProduction = "__Host-mreact.csrf";
|
|
|
2
2
|
const csrfCookieNameDevelopment = "mreact.csrf";
|
|
3
3
|
const formFieldCsrf = "__mreact_csrf";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Names the hidden form field used for app-router CSRF validation.
|
|
7
|
+
*/
|
|
5
8
|
export const formCsrfFieldName = formFieldCsrf;
|
|
6
9
|
|
|
7
10
|
export function serverActionCookie(csrfToken: string): string {
|
|
@@ -20,14 +23,23 @@ export function serverActionCookie(csrfToken: string): string {
|
|
|
20
23
|
return parts.join("; ");
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Creates or reuses the CSRF token embedded into server-rendered forms.
|
|
28
|
+
*/
|
|
23
29
|
export function createFormCsrfToken(request?: Request | undefined): string {
|
|
24
30
|
return readExistingFormCsrfToken(request) ?? randomToken();
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Serializes the CSRF cookie used to validate app-router form submissions.
|
|
35
|
+
*/
|
|
27
36
|
export function formCsrfCookie(csrfToken: string): string {
|
|
28
37
|
return serverActionCookie(csrfToken);
|
|
29
38
|
}
|
|
30
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Validates the CSRF cookie and hidden form field for a form submission.
|
|
42
|
+
*/
|
|
31
43
|
export function validateFormCsrf(request: Request, formData: FormData): Response | undefined {
|
|
32
44
|
const formToken = stringFormValue(formData.get(formFieldCsrf));
|
|
33
45
|
const cookieHeader = request.headers.get("cookie");
|
package/src/deferred.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
const deferredLoaderDataSymbol = Symbol.for("mreact.router.deferred-loader-data");
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Marks loader data that contains streamed deferred values.
|
|
5
|
+
*/
|
|
3
6
|
export type DeferredLoaderData<TData extends Record<string, unknown>> = TData & {
|
|
4
7
|
readonly [deferredLoaderDataSymbol]: true;
|
|
5
8
|
};
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Marks loader data for deferred streaming without changing its data shape.
|
|
12
|
+
*/
|
|
7
13
|
export function defer<TData extends Record<string, unknown>>(
|
|
8
14
|
data: TData,
|
|
9
15
|
): DeferredLoaderData<TData> {
|
|
@@ -15,6 +21,9 @@ export function defer<TData extends Record<string, unknown>>(
|
|
|
15
21
|
}) as DeferredLoaderData<TData>;
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether loader data was marked with `defer()`.
|
|
26
|
+
*/
|
|
18
27
|
export function isDeferredLoaderData(
|
|
19
28
|
value: unknown,
|
|
20
29
|
): value is DeferredLoaderData<Record<string, unknown>> {
|
package/src/dev-server.ts
CHANGED
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
} from "./logger.js";
|
|
22
22
|
import type { HttpUpgradeHandler } from "./upgrade.js";
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Configures the Vite-powered app-router development server.
|
|
26
|
+
*/
|
|
24
27
|
export interface StartDevServerOptions extends AppRouterProjectOptions {
|
|
25
28
|
port?: number | undefined;
|
|
26
29
|
hostname?: string;
|
package/src/file-conventions.ts
CHANGED
package/src/i18n.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configures locale detection for app-router requests.
|
|
3
|
+
*/
|
|
1
4
|
export interface LocaleRoutingOptions<Locale extends string = string> {
|
|
2
5
|
defaultLocale: Locale;
|
|
3
6
|
locales: readonly Locale[];
|
|
4
7
|
}
|
|
5
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Reports the locale selected for an incoming request.
|
|
11
|
+
*/
|
|
6
12
|
export interface DetectedLocale<Locale extends string = string> {
|
|
7
13
|
locale: Locale;
|
|
8
14
|
pathname: string;
|
|
9
15
|
source: "accept-language" | "default" | "path";
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Describes a nested tree of localized message strings.
|
|
20
|
+
*/
|
|
12
21
|
export type MessageTree = {
|
|
13
22
|
readonly [key: string]: MessageTree | string;
|
|
14
23
|
};
|
|
15
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Detects the request locale from the URL path or Accept-Language header.
|
|
27
|
+
*/
|
|
16
28
|
export function detectLocale<Locale extends string>(
|
|
17
29
|
request: Request,
|
|
18
30
|
options: LocaleRoutingOptions<Locale>,
|
|
@@ -48,6 +60,9 @@ export function detectLocale<Locale extends string>(
|
|
|
48
60
|
};
|
|
49
61
|
}
|
|
50
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Preserves literal types for a localized message tree.
|
|
65
|
+
*/
|
|
51
66
|
export function defineMessages<const Messages extends MessageTree>(messages: Messages): Messages {
|
|
52
67
|
return messages;
|
|
53
68
|
}
|
package/src/import-policy.ts
CHANGED
|
@@ -12,6 +12,9 @@ const alwaysAllowedPackages = new Set([
|
|
|
12
12
|
"@reckona/mreact-router",
|
|
13
13
|
]);
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Controls which source roots and runtime packages built app-router handlers may import.
|
|
17
|
+
*/
|
|
15
18
|
export interface AppRouterImportPolicy {
|
|
16
19
|
allowedPackages?: readonly string[] | undefined;
|
|
17
20
|
allowedSourceDirs?: readonly string[] | undefined;
|
package/src/index.ts
CHANGED
|
@@ -53,22 +53,32 @@ import type {
|
|
|
53
53
|
} from "./session.js";
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
+
* Creates a deprecated process-local session store alias.
|
|
57
|
+
*
|
|
56
58
|
* @deprecated Import session helpers from `@reckona/mreact-auth` instead.
|
|
57
59
|
*/
|
|
58
60
|
export const createMemorySessionStore = createMemorySessionStoreInternal;
|
|
59
61
|
/**
|
|
62
|
+
* Creates a deprecated session record and cookie alias.
|
|
63
|
+
*
|
|
60
64
|
* @deprecated Import session helpers from `@reckona/mreact-auth` instead.
|
|
61
65
|
*/
|
|
62
66
|
export const createSession = createSessionInternal;
|
|
63
67
|
/**
|
|
68
|
+
* Destroys a session through a deprecated router session alias.
|
|
69
|
+
*
|
|
64
70
|
* @deprecated Import session helpers from `@reckona/mreact-auth` instead.
|
|
65
71
|
*/
|
|
66
72
|
export const destroySession = destroySessionInternal;
|
|
67
73
|
/**
|
|
74
|
+
* Reads a session through a deprecated router session alias.
|
|
75
|
+
*
|
|
68
76
|
* @deprecated Import session helpers from `@reckona/mreact-auth` instead.
|
|
69
77
|
*/
|
|
70
78
|
export const getSession = getSessionInternal;
|
|
71
79
|
/**
|
|
80
|
+
* Rotates a session through a deprecated router session alias.
|
|
81
|
+
*
|
|
72
82
|
* @deprecated Import session helpers from `@reckona/mreact-auth` instead.
|
|
73
83
|
*/
|
|
74
84
|
export const rotateSession = rotateSessionInternal;
|
|
@@ -148,6 +158,7 @@ export type {
|
|
|
148
158
|
} from "./cache.js";
|
|
149
159
|
export type { CookieOptions } from "./cookies.js";
|
|
150
160
|
export type { AppRouterImportPolicy } from "./import-policy.js";
|
|
161
|
+
/** Re-exports link types used by the router root entrypoint. */
|
|
151
162
|
export type {
|
|
152
163
|
AppRouteDeclarations,
|
|
153
164
|
ConcreteLinkHrefGuard,
|
|
@@ -161,12 +172,14 @@ export type {
|
|
|
161
172
|
LinkTransition,
|
|
162
173
|
TrustedLinkHtml,
|
|
163
174
|
} from "./link.js";
|
|
175
|
+
/** Re-exports client navigation state types used by the router root entrypoint. */
|
|
164
176
|
export type {
|
|
165
177
|
AppRouterNavigationState,
|
|
166
178
|
AppRouterNavigationStateListener,
|
|
167
179
|
AppRouterNavigationType,
|
|
168
180
|
} from "./navigation-state.js";
|
|
169
181
|
export type { RouterRuntimeCacheStat } from "./runtime-cache.js";
|
|
182
|
+
/** Configures the deprecated router memory session store alias. */
|
|
170
183
|
export type { MemorySessionStoreOptionsInternal as MemorySessionStoreOptions };
|
|
171
184
|
export type {
|
|
172
185
|
AppRouterCspInlineNonceWarningLogEvent,
|
|
@@ -194,14 +207,20 @@ export type {
|
|
|
194
207
|
PreparedFormActionReference,
|
|
195
208
|
} from "./actions.js";
|
|
196
209
|
/**
|
|
210
|
+
* Configures the deprecated router session cookie alias.
|
|
211
|
+
*
|
|
197
212
|
* @deprecated Import session helpers and types from `@reckona/mreact-auth` instead.
|
|
198
213
|
*/
|
|
199
214
|
export type SessionCookieOptions = SessionCookieOptionsInternal;
|
|
200
215
|
/**
|
|
216
|
+
* Stores session data through the deprecated router session record alias.
|
|
217
|
+
*
|
|
201
218
|
* @deprecated Import session helpers and types from `@reckona/mreact-auth` instead.
|
|
202
219
|
*/
|
|
203
220
|
export type SessionRecord<TData = unknown> = SessionRecordInternal<TData>;
|
|
204
221
|
/**
|
|
222
|
+
* Defines session persistence through the deprecated router session store alias.
|
|
223
|
+
*
|
|
205
224
|
* @deprecated Import session helpers and types from `@reckona/mreact-auth` instead.
|
|
206
225
|
*/
|
|
207
226
|
export type SessionStore<TData = unknown> = SessionStoreInternal<TData>;
|
package/src/link.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { HtmlSink } from "@reckona/mreact-shared/compiler-contract";
|
|
|
3
3
|
import type { ReactCompatElement, ReactCompatNode } from "@reckona/mreact-compat";
|
|
4
4
|
import { safeUrlAttributeValue } from "@reckona/mreact-shared/url-safety";
|
|
5
5
|
import type { AppRouteLinkHref } from "./typed-routes.js";
|
|
6
|
+
/** Re-exports typed route href helper types used by Link. */
|
|
6
7
|
export type {
|
|
7
8
|
AppRouteLinkHref,
|
|
8
9
|
AppRouteLinkHrefSuffix,
|
|
@@ -13,19 +14,46 @@ export type {
|
|
|
13
14
|
|
|
14
15
|
const TRUSTED_LINK_HTML = Symbol.for("modular.react.router.trusted_link_html");
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Selects when the app router should prefetch a linked route.
|
|
19
|
+
*/
|
|
16
20
|
export type LinkPrefetch = "intent" | "viewport" | "none" | false;
|
|
21
|
+
/**
|
|
22
|
+
* Controls scroll restoration behavior after client navigation.
|
|
23
|
+
*/
|
|
17
24
|
export type LinkScroll = "top" | "preserve";
|
|
25
|
+
/**
|
|
26
|
+
* Controls whether client navigation participates in view transitions.
|
|
27
|
+
*/
|
|
18
28
|
export type LinkTransition = "auto" | "none" | false;
|
|
29
|
+
/**
|
|
30
|
+
* Wraps pre-escaped HTML that can be used as trusted link children.
|
|
31
|
+
*/
|
|
19
32
|
export type TrustedLinkHtml = { readonly [TRUSTED_LINK_HTML]: string };
|
|
33
|
+
/**
|
|
34
|
+
* Represents children accepted by the app-router Link renderer.
|
|
35
|
+
*/
|
|
20
36
|
export type LinkChild = ReactCompatNode | Node | TrustedLinkHtml | readonly LinkChild[];
|
|
37
|
+
/**
|
|
38
|
+
* Allows applications to augment statically registered app route paths through `@reckona/mreact-router/link`.
|
|
39
|
+
*/
|
|
21
40
|
export interface AppRouteDeclarations {}
|
|
41
|
+
/**
|
|
42
|
+
* Extracts registered route paths from `AppRouteDeclarations`.
|
|
43
|
+
*/
|
|
22
44
|
export type RegisteredAppRoutePath = AppRouteDeclarations extends { readonly path: infer Path }
|
|
23
45
|
? Extract<Path, `/${string}`>
|
|
24
46
|
: never;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the accepted `href` type for app-router links.
|
|
49
|
+
*/
|
|
25
50
|
export type LinkHref = [RegisteredAppRoutePath] extends [never]
|
|
26
51
|
? string
|
|
27
52
|
: AppRouteLinkHref<RegisteredAppRoutePath>;
|
|
28
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Configures client navigation behavior for a router link.
|
|
56
|
+
*/
|
|
29
57
|
export interface LinkOptions<Href extends string = LinkHref> {
|
|
30
58
|
href: Href;
|
|
31
59
|
prefetch?: LinkPrefetch | undefined;
|
|
@@ -34,6 +62,9 @@ export interface LinkOptions<Href extends string = LinkHref> {
|
|
|
34
62
|
transition?: LinkTransition | undefined;
|
|
35
63
|
}
|
|
36
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Combines router link options with anchor attributes and children.
|
|
67
|
+
*/
|
|
37
68
|
export interface LinkProps<Href extends string = LinkHref> extends LinkOptions<Href> {
|
|
38
69
|
children?: LinkChild;
|
|
39
70
|
[attribute: string]: unknown;
|
|
@@ -60,6 +91,9 @@ export function linkProps(options: LinkOptions<string>): Record<string, string>
|
|
|
60
91
|
};
|
|
61
92
|
}
|
|
62
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Produces a compile-time error shape when a typed Link receives an unresolved route pattern.
|
|
96
|
+
*/
|
|
63
97
|
export type ConcreteLinkHrefGuard<Href extends string> = [RegisteredAppRoutePath] extends [never]
|
|
64
98
|
? unknown
|
|
65
99
|
: Href extends Extract<RegisteredAppRoutePath, `${string}:${string}`>
|