@reckona/mreact-router 0.0.160 → 0.0.162
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/logger.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names the severity channel used for app-router structured logs.
|
|
3
|
+
*/
|
|
1
4
|
export type AppRouterLogLevel = "debug" | "info" | "warn" | "error";
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Names the runtime that handled an app-router request.
|
|
8
|
+
*/
|
|
3
9
|
export type AppRouterRuntime = "aws-lambda" | "cloudflare" | "edge" | "node";
|
|
4
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Receives structured app-router log events by severity.
|
|
13
|
+
*/
|
|
5
14
|
export interface AppRouterLogger {
|
|
6
15
|
debug?: ((event: AppRouterLogEvent) => void | Promise<void>) | undefined;
|
|
7
16
|
error?: ((event: AppRouterLogEvent) => void | Promise<void>) | undefined;
|
|
@@ -9,6 +18,9 @@ export interface AppRouterLogger {
|
|
|
9
18
|
warn?: ((event: AppRouterLogEvent) => void | Promise<void>) | undefined;
|
|
10
19
|
}
|
|
11
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Represents every structured log event emitted by the app router.
|
|
23
|
+
*/
|
|
12
24
|
export type AppRouterLogEvent =
|
|
13
25
|
| AppRouterRequestStartLogEvent
|
|
14
26
|
| AppRouterRequestEndLogEvent
|
|
@@ -17,6 +29,9 @@ export type AppRouterLogEvent =
|
|
|
17
29
|
| AppRouterRenderTimingLogEvent
|
|
18
30
|
| AppRouterCspInlineNonceWarningLogEvent;
|
|
19
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Logs the start of an app-router request.
|
|
34
|
+
*/
|
|
20
35
|
export interface AppRouterRequestStartLogEvent {
|
|
21
36
|
method: string;
|
|
22
37
|
path: string;
|
|
@@ -24,6 +39,9 @@ export interface AppRouterRequestStartLogEvent {
|
|
|
24
39
|
type: "router:request:start";
|
|
25
40
|
}
|
|
26
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Logs the successful completion of an app-router request.
|
|
44
|
+
*/
|
|
27
45
|
export interface AppRouterRequestEndLogEvent {
|
|
28
46
|
durationMs: number;
|
|
29
47
|
method: string;
|
|
@@ -33,6 +51,9 @@ export interface AppRouterRequestEndLogEvent {
|
|
|
33
51
|
type: "router:request:end";
|
|
34
52
|
}
|
|
35
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Logs a request that ended with an app-router error response.
|
|
56
|
+
*/
|
|
36
57
|
export interface AppRouterRequestErrorLogEvent {
|
|
37
58
|
durationMs: number;
|
|
38
59
|
error: AppRouterLogError;
|
|
@@ -42,6 +63,9 @@ export interface AppRouterRequestErrorLogEvent {
|
|
|
42
63
|
type: "router:request:error";
|
|
43
64
|
}
|
|
44
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Logs per-phase timings for a complete app-router request.
|
|
68
|
+
*/
|
|
45
69
|
export interface AppRouterRequestTimingLogEvent {
|
|
46
70
|
durationMs: number;
|
|
47
71
|
method: string;
|
|
@@ -52,6 +76,9 @@ export interface AppRouterRequestTimingLogEvent {
|
|
|
52
76
|
type: "router:request:timing";
|
|
53
77
|
}
|
|
54
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Logs per-phase timings for route rendering.
|
|
81
|
+
*/
|
|
55
82
|
export interface AppRouterRenderTimingLogEvent {
|
|
56
83
|
method: string;
|
|
57
84
|
path: string;
|
|
@@ -60,6 +87,9 @@ export interface AppRouterRenderTimingLogEvent {
|
|
|
60
87
|
type: "router:render:timing";
|
|
61
88
|
}
|
|
62
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Logs an inline CSP nonce warning emitted while rendering a route.
|
|
92
|
+
*/
|
|
63
93
|
export interface AppRouterCspInlineNonceWarningLogEvent {
|
|
64
94
|
directive: "script-src" | "style-src";
|
|
65
95
|
path: string;
|
|
@@ -67,6 +97,9 @@ export interface AppRouterCspInlineNonceWarningLogEvent {
|
|
|
67
97
|
type: "router:csp:inline-nonce-warning";
|
|
68
98
|
}
|
|
69
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Serializes an error for app-router structured logs.
|
|
102
|
+
*/
|
|
70
103
|
export interface AppRouterLogError {
|
|
71
104
|
message: string;
|
|
72
105
|
name: string;
|
package/src/multipart.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configures multipart stream parsing limits and field handling.
|
|
3
|
+
*/
|
|
1
4
|
export interface MultipartStreamParseOptions {
|
|
2
5
|
fields?: Readonly<Record<string, MultipartStreamFieldOptions>>;
|
|
3
6
|
maxParts?: number;
|
|
4
7
|
maxBytes?: number;
|
|
5
8
|
}
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Configures parsing behavior for a named multipart field.
|
|
12
|
+
*/
|
|
7
13
|
export interface MultipartStreamFieldOptions {
|
|
8
14
|
type?: "stream" | "text";
|
|
9
15
|
maxBytes?: number;
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Represents one parsed multipart field or file part.
|
|
20
|
+
*/
|
|
12
21
|
export interface MultipartStreamPart {
|
|
13
22
|
name: string;
|
|
14
23
|
filename?: string;
|
|
@@ -21,6 +30,9 @@ export interface MultipartStreamPart {
|
|
|
21
30
|
fixedLengthStream(length?: number | bigint): MultipartFixedLengthStream;
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Couples a readable multipart part stream with a completion signal.
|
|
35
|
+
*/
|
|
24
36
|
export interface MultipartFixedLengthStream {
|
|
25
37
|
readable: ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
26
38
|
done: Promise<void>;
|
|
@@ -39,6 +51,9 @@ const maxHeaderBytes = 64 * 1024;
|
|
|
39
51
|
export const defaultMultipartMaxBytes = 10 * 1024 * 1024;
|
|
40
52
|
export const defaultMultipartMaxParts = 1_000;
|
|
41
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Parses a multipart request body as an async iterable of streamable parts.
|
|
56
|
+
*/
|
|
42
57
|
export function parseMultipartStream(
|
|
43
58
|
request: Request,
|
|
44
59
|
options: MultipartStreamParseOptions = {},
|
package/src/native-escape.ts
CHANGED
|
@@ -9,6 +9,9 @@ interface NativeEscapeModule {
|
|
|
9
9
|
let nativeModule: NativeEscapeModule | false | undefined;
|
|
10
10
|
let nativeRequire: ReturnType<typeof createRequire> | false | undefined;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Escapes a batch of values as HTML text using the native helper when available.
|
|
14
|
+
*/
|
|
12
15
|
export function escapeHtmlBatch(values: readonly unknown[]): string[] {
|
|
13
16
|
const strings = values.map((value) => String(value ?? ""));
|
|
14
17
|
const native = loadNativeEscapeModule();
|
package/src/navigation-state.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names the client navigation operation that produced the current router state.
|
|
3
|
+
*/
|
|
1
4
|
export type AppRouterNavigationType = "push" | "replace" | "pop" | "refresh";
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Describes the latest client-side app-router navigation state.
|
|
8
|
+
*/
|
|
3
9
|
export interface AppRouterNavigationState {
|
|
4
10
|
pending: boolean;
|
|
5
11
|
from: string | null;
|
|
@@ -7,6 +13,9 @@ export interface AppRouterNavigationState {
|
|
|
7
13
|
type: AppRouterNavigationType | null;
|
|
8
14
|
}
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Receives app-router client navigation state updates.
|
|
18
|
+
*/
|
|
10
19
|
export type AppRouterNavigationStateListener = (
|
|
11
20
|
state: AppRouterNavigationState,
|
|
12
21
|
) => void;
|
|
@@ -18,6 +27,9 @@ const idleNavigationState: AppRouterNavigationState = {
|
|
|
18
27
|
type: null,
|
|
19
28
|
};
|
|
20
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Reads the current client navigation state snapshot.
|
|
32
|
+
*/
|
|
21
33
|
export function getNavigationState(): AppRouterNavigationState {
|
|
22
34
|
const runtimeState = (globalThis as {
|
|
23
35
|
__mreactNavigationState?: { current?: unknown };
|
|
@@ -31,6 +43,9 @@ export function getNavigationState(): AppRouterNavigationState {
|
|
|
31
43
|
return navigationStateFromDocument();
|
|
32
44
|
}
|
|
33
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Subscribes to app-router client navigation state changes.
|
|
48
|
+
*/
|
|
34
49
|
export function subscribeNavigationState(
|
|
35
50
|
listener: AppRouterNavigationStateListener,
|
|
36
51
|
): () => void {
|
package/src/navigation.ts
CHANGED
|
@@ -11,6 +11,9 @@ export interface RedirectOptions {
|
|
|
11
11
|
|
|
12
12
|
export type MiddlewareNext = undefined;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Describes a parser used by `parseForm()` to validate submitted form data.
|
|
16
|
+
*/
|
|
14
17
|
export interface ParseSchema<T> {
|
|
15
18
|
parse(value: FormData): T;
|
|
16
19
|
}
|
|
@@ -270,12 +273,18 @@ export function rewriteLocation(response: Response): string | undefined {
|
|
|
270
273
|
return candidate !== undefined && isSafeInternalRedirect(candidate) ? candidate : undefined;
|
|
271
274
|
}
|
|
272
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Checks whether an unknown error is an app-router redirect signal.
|
|
278
|
+
*/
|
|
273
279
|
export function isRedirectError(error: unknown): error is Error & { location: string; status: number } {
|
|
274
280
|
return error instanceof Error &&
|
|
275
281
|
error.name === redirectErrorName &&
|
|
276
282
|
typeof (error as { location?: unknown }).location === "string";
|
|
277
283
|
}
|
|
278
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Checks whether an unknown error is an app-router not-found signal.
|
|
287
|
+
*/
|
|
279
288
|
export function isNotFoundError(error: unknown): boolean {
|
|
280
289
|
return error instanceof Error && error.name === notFoundErrorName;
|
|
281
290
|
}
|
package/src/prerender-store.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import type { BuiltPrerenderedRoute } from "./build.js";
|
|
5
5
|
import type { AppRouterPrerenderStore } from "./serve.js";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Configures the process-local prerender store used for cached prerendered routes.
|
|
9
|
+
*/
|
|
7
10
|
export interface MemoryPrerenderStoreOptions {
|
|
8
11
|
backing?: Map<string, MemoryPrerenderStoreEntry>;
|
|
9
12
|
maxEntries?: number;
|
|
@@ -18,6 +21,9 @@ export interface MemoryPrerenderStoreEntry {
|
|
|
18
21
|
lastAccessedAt: number;
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Configures a filesystem-backed prerender store.
|
|
26
|
+
*/
|
|
21
27
|
export interface FileSystemPrerenderStoreOptions {
|
|
22
28
|
directory: string;
|
|
23
29
|
lockPollMs?: number;
|
|
@@ -25,6 +31,9 @@ export interface FileSystemPrerenderStoreOptions {
|
|
|
25
31
|
namespace?: string;
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Defines the adapter API used by key-value prerender stores.
|
|
36
|
+
*/
|
|
28
37
|
export interface KeyValuePrerenderStoreAdapter {
|
|
29
38
|
delete(key: string): void | Promise<void>;
|
|
30
39
|
get(key: string): string | undefined | Promise<string | undefined>;
|
|
@@ -32,12 +41,18 @@ export interface KeyValuePrerenderStoreAdapter {
|
|
|
32
41
|
withLock?<T>(key: string, task: (token: string) => Promise<T>): Promise<T>;
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Configures a key-value-backed prerender store.
|
|
46
|
+
*/
|
|
35
47
|
export interface KeyValuePrerenderStoreOptions {
|
|
36
48
|
adapter: KeyValuePrerenderStoreAdapter;
|
|
37
49
|
namespace?: string;
|
|
38
50
|
ttlMs?: number;
|
|
39
51
|
}
|
|
40
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Creates an in-memory prerender store with optional TTL and LRU eviction.
|
|
55
|
+
*/
|
|
41
56
|
export function createMemoryPrerenderStore(
|
|
42
57
|
options: MemoryPrerenderStoreOptions = {},
|
|
43
58
|
): AppRouterPrerenderStore {
|
|
@@ -100,6 +115,9 @@ export function createMemoryPrerenderStore(
|
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Creates a prerender store that persists entries as JSON files.
|
|
120
|
+
*/
|
|
103
121
|
export function createFileSystemPrerenderStore(
|
|
104
122
|
options: FileSystemPrerenderStoreOptions,
|
|
105
123
|
): AppRouterPrerenderStore {
|
|
@@ -162,6 +180,9 @@ export function createFileSystemPrerenderStore(
|
|
|
162
180
|
};
|
|
163
181
|
}
|
|
164
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Creates a prerender store backed by a caller-provided key-value adapter.
|
|
185
|
+
*/
|
|
165
186
|
export function createKeyValuePrerenderStore(
|
|
166
187
|
options: KeyValuePrerenderStoreOptions,
|
|
167
188
|
): AppRouterPrerenderStore {
|
package/src/render.ts
CHANGED
|
@@ -163,6 +163,9 @@ interface RenderTiming {
|
|
|
163
163
|
phases: Record<string, number>;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Configures server rendering for a source app-router request.
|
|
168
|
+
*/
|
|
166
169
|
export interface RenderAppRequestOptions {
|
|
167
170
|
appDir: string;
|
|
168
171
|
assetBaseUrl?: string | undefined;
|
|
@@ -204,11 +207,17 @@ export interface AppRouterRenderPreload {
|
|
|
204
207
|
wait: "before-render";
|
|
205
208
|
}
|
|
206
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Allows callers to inspect or replace an app-router response before it is returned.
|
|
212
|
+
*/
|
|
207
213
|
export type AppRouterResponseHook = (
|
|
208
214
|
response: Response,
|
|
209
215
|
context: AppRouterResponseHookContext,
|
|
210
216
|
) => Response | undefined | void | Promise<Response | undefined | void>;
|
|
211
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Provides request context to an app-router response hook.
|
|
220
|
+
*/
|
|
212
221
|
export interface AppRouterResponseHookContext {
|
|
213
222
|
request: Request;
|
|
214
223
|
}
|
|
@@ -603,6 +612,9 @@ interface RouteSourceAnalysis {
|
|
|
603
612
|
usesRuntimeCacheControl: boolean;
|
|
604
613
|
}
|
|
605
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Renders a source app-router request into a `Response`.
|
|
617
|
+
*/
|
|
606
618
|
export async function renderAppRequest(options: RenderAppRequestOptions): Promise<Response> {
|
|
607
619
|
const authStorage = authRequestStorage();
|
|
608
620
|
|
package/src/routes.ts
CHANGED
|
@@ -6,12 +6,21 @@ import {
|
|
|
6
6
|
type AppFileConvention,
|
|
7
7
|
} from "./file-conventions.js";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Configures app route discovery from a routes directory.
|
|
11
|
+
*/
|
|
9
12
|
export interface ScanAppRoutesOptions {
|
|
10
13
|
appDir: string;
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Represents any route discovered by the app-router file-system scanner.
|
|
18
|
+
*/
|
|
13
19
|
export type AppRoute = AppAssetRoute | AppMetadataRoute | PageRoute | ServerRoute;
|
|
14
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Describes a page route that renders a component.
|
|
23
|
+
*/
|
|
15
24
|
export interface PageRoute {
|
|
16
25
|
kind: "page";
|
|
17
26
|
path: string;
|
|
@@ -19,6 +28,9 @@ export interface PageRoute {
|
|
|
19
28
|
segments: RouteSegment[];
|
|
20
29
|
}
|
|
21
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Describes a server route that handles HTTP methods directly.
|
|
33
|
+
*/
|
|
22
34
|
export interface ServerRoute {
|
|
23
35
|
kind: "server";
|
|
24
36
|
path: string;
|
|
@@ -26,6 +38,9 @@ export interface ServerRoute {
|
|
|
26
38
|
segments: RouteSegment[];
|
|
27
39
|
}
|
|
28
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Describes a generated metadata route such as robots or sitemap.
|
|
43
|
+
*/
|
|
29
44
|
export interface AppMetadataRoute {
|
|
30
45
|
convention: AppFileConvention;
|
|
31
46
|
kind: "metadata";
|
|
@@ -34,6 +49,9 @@ export interface AppMetadataRoute {
|
|
|
34
49
|
segments: RouteSegment[];
|
|
35
50
|
}
|
|
36
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Describes a static asset route produced from an app file convention.
|
|
54
|
+
*/
|
|
37
55
|
export interface AppAssetRoute {
|
|
38
56
|
convention: AppFileConvention;
|
|
39
57
|
kind: "asset";
|
|
@@ -42,11 +60,17 @@ export interface AppAssetRoute {
|
|
|
42
60
|
segments: RouteSegment[];
|
|
43
61
|
}
|
|
44
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Represents a static, dynamic, or catch-all segment in an app route path.
|
|
65
|
+
*/
|
|
45
66
|
export type RouteSegment =
|
|
46
67
|
| { kind: "static"; value: string }
|
|
47
68
|
| { kind: "dynamic"; name: string }
|
|
48
69
|
| { kind: "catch-all"; name: string };
|
|
49
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Holds the route and params selected for a request pathname.
|
|
73
|
+
*/
|
|
50
74
|
export interface MatchedRoute {
|
|
51
75
|
route: AppRoute;
|
|
52
76
|
params: Record<string, readonly string[] | string>;
|
|
@@ -56,6 +80,9 @@ export interface RouteMatcher {
|
|
|
56
80
|
match(pathname: string): MatchedRoute | undefined;
|
|
57
81
|
}
|
|
58
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Scans an app directory and returns sorted app-router route definitions.
|
|
85
|
+
*/
|
|
59
86
|
export async function scanAppRoutes(
|
|
60
87
|
options: ScanAppRoutesOptions,
|
|
61
88
|
): Promise<AppRoute[]> {
|
|
@@ -84,6 +111,9 @@ export async function scanAppRoutes(
|
|
|
84
111
|
.sort(compareRouteListEntries);
|
|
85
112
|
}
|
|
86
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Matches a request pathname against a route list.
|
|
116
|
+
*/
|
|
87
117
|
export function matchRoute(
|
|
88
118
|
routes: readonly AppRoute[],
|
|
89
119
|
pathname: string,
|
package/src/runtime-cache.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { routerModuleRunnerRuntimeCacheStats } from "./module-runner.js";
|
|
2
2
|
import { routerRenderRuntimeCacheStats } from "./render.js";
|
|
3
3
|
import type { RouterRuntimeCacheStat } from "./cache-stats.js";
|
|
4
|
+
|
|
5
|
+
/** Reports a named runtime cache and its current entry count. */
|
|
4
6
|
export type { RouterRuntimeCacheStat } from "./cache-stats.js";
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Reads app-router runtime cache sizes for diagnostics.
|
|
10
|
+
*/
|
|
6
11
|
export function getRouterRuntimeCacheStats(): RouterRuntimeCacheStat[] {
|
|
7
12
|
return [...routerRenderRuntimeCacheStats(), ...routerModuleRunnerRuntimeCacheStats()];
|
|
8
13
|
}
|
package/src/runtime-state.ts
CHANGED
|
@@ -3,6 +3,9 @@ type RuntimeStateRoot = Record<string, unknown>;
|
|
|
3
3
|
|
|
4
4
|
const namespace = "__mreactRouterRuntimeState";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Reads or initializes shared server runtime state stored on `globalThis`.
|
|
8
|
+
*/
|
|
6
9
|
export function getServerRuntimeState<TState extends object>(
|
|
7
10
|
key: string,
|
|
8
11
|
create: () => TState,
|
package/src/serve.ts
CHANGED
|
@@ -119,10 +119,16 @@ interface BuiltPublicAsset {
|
|
|
119
119
|
* that on your workload.
|
|
120
120
|
*/
|
|
121
121
|
export type ResponseSinkStrategy = "string" | "buffer";
|
|
122
|
+
/**
|
|
123
|
+
* Controls whether built request handling trusts the incoming Host header.
|
|
124
|
+
*/
|
|
122
125
|
export type RequestHostPolicy = "strict" | "trusted-proxy";
|
|
123
126
|
|
|
124
127
|
let warnedImplicitHostTrust = false;
|
|
125
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Configures rendering a request against a built app-router output directory.
|
|
131
|
+
*/
|
|
126
132
|
export interface RenderBuiltAppRequestOptions {
|
|
127
133
|
outDir: string;
|
|
128
134
|
importPolicy?: AppRouterImportPolicy | undefined;
|
|
@@ -159,6 +165,9 @@ export interface BuiltRequestRuntime {
|
|
|
159
165
|
): Promise<Response>;
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Selects which built runtime modules should be preloaded.
|
|
170
|
+
*/
|
|
162
171
|
export type BuiltAppRuntimePreloadMode =
|
|
163
172
|
| "all"
|
|
164
173
|
| "hot-route-requests"
|
|
@@ -166,11 +175,17 @@ export type BuiltAppRuntimePreloadMode =
|
|
|
166
175
|
| "middleware"
|
|
167
176
|
| "none";
|
|
168
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Configures built app runtime preload scope and optional hot routes.
|
|
180
|
+
*/
|
|
169
181
|
export interface BuiltAppRuntimePreloadStrategy {
|
|
170
182
|
mode: BuiltAppRuntimePreloadMode;
|
|
171
183
|
routes?: readonly string[] | undefined;
|
|
172
184
|
}
|
|
173
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Configures the Node HTTP server used to serve a built app-router output.
|
|
188
|
+
*/
|
|
174
189
|
export interface StartServerOptions {
|
|
175
190
|
outDir: string;
|
|
176
191
|
port: number;
|
|
@@ -232,6 +247,9 @@ export function warnIfImplicitHostTrust(options: {
|
|
|
232
247
|
);
|
|
233
248
|
}
|
|
234
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Defines storage for prerendered route responses used by built request rendering.
|
|
252
|
+
*/
|
|
235
253
|
export interface AppRouterPrerenderStore {
|
|
236
254
|
delete(path: string): void | Promise<void>;
|
|
237
255
|
get(path: string): BuiltPrerenderedRoute | undefined | Promise<BuiltPrerenderedRoute | undefined>;
|
|
@@ -277,6 +295,9 @@ export async function createBuiltRequestRuntime(
|
|
|
277
295
|
};
|
|
278
296
|
}
|
|
279
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Preloads selected modules from a built app-router runtime.
|
|
300
|
+
*/
|
|
280
301
|
export async function preloadBuiltAppRuntime(options: {
|
|
281
302
|
importPolicy?: AppRouterImportPolicy | undefined;
|
|
282
303
|
outDir: string;
|
|
@@ -363,6 +384,9 @@ function builtRuntimePreloadRoutes(
|
|
|
363
384
|
});
|
|
364
385
|
}
|
|
365
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Renders a request using a built app-router output directory.
|
|
389
|
+
*/
|
|
366
390
|
export async function renderBuiltAppRequest(
|
|
367
391
|
options: RenderBuiltAppRequestOptions,
|
|
368
392
|
): Promise<Response> {
|
package/src/session.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { deleteCookie, parseCookieHeader, setCookie } from "./cookies.js";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Stores session data and expiration metadata for one session id.
|
|
5
|
+
*/
|
|
3
6
|
export interface SessionRecord<TData = unknown> {
|
|
4
7
|
createdAt: number;
|
|
5
8
|
data: TData;
|
|
@@ -8,17 +11,26 @@ export interface SessionRecord<TData = unknown> {
|
|
|
8
11
|
rotatedAt?: number;
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Defines the persistence API used by app-router session helpers.
|
|
16
|
+
*/
|
|
11
17
|
export interface SessionStore<TData = unknown> {
|
|
12
18
|
delete(id: string): void | Promise<void>;
|
|
13
19
|
get(id: string): SessionRecord<TData> | undefined | Promise<SessionRecord<TData> | undefined>;
|
|
14
20
|
set(record: SessionRecord<TData>): void | Promise<void>;
|
|
15
21
|
}
|
|
16
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Configures the process-local memory session store.
|
|
25
|
+
*/
|
|
17
26
|
export interface MemorySessionStoreOptions {
|
|
18
27
|
maxEntries?: number;
|
|
19
28
|
sweepIntervalMs?: number;
|
|
20
29
|
}
|
|
21
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Configures the cookie used by app-router session helpers.
|
|
33
|
+
*/
|
|
22
34
|
export interface SessionCookieOptions {
|
|
23
35
|
cookieName?: string;
|
|
24
36
|
maxAgeSeconds?: number;
|
package/src/stream-list.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents one resolved batch emitted by `streamList()`.
|
|
3
|
+
*/
|
|
1
4
|
export interface StreamListBatch<TItem> {
|
|
2
5
|
index: number;
|
|
3
6
|
items: TItem[];
|
|
@@ -5,6 +8,9 @@ export interface StreamListBatch<TItem> {
|
|
|
5
8
|
start: number;
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Represents one pending batch and its eventual loaded items.
|
|
13
|
+
*/
|
|
8
14
|
export interface StreamListPendingBatch<TItem> {
|
|
9
15
|
index: number;
|
|
10
16
|
size: number;
|
|
@@ -12,6 +18,9 @@ export interface StreamListPendingBatch<TItem> {
|
|
|
12
18
|
value: Promise<StreamListBatch<TItem>>;
|
|
13
19
|
}
|
|
14
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Configures how a list is divided into asynchronous batches.
|
|
23
|
+
*/
|
|
15
24
|
export interface StreamListOptions<TInput, TItem> {
|
|
16
25
|
batchSize: number;
|
|
17
26
|
loadBatch: (
|
|
@@ -20,6 +29,9 @@ export interface StreamListOptions<TInput, TItem> {
|
|
|
20
29
|
) => PromiseLike<readonly TItem[]> | readonly TItem[];
|
|
21
30
|
}
|
|
22
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Splits an input list into pending batches that load their items asynchronously.
|
|
34
|
+
*/
|
|
23
35
|
export function streamList<TInput, TItem = TInput>(
|
|
24
36
|
items: readonly TInput[],
|
|
25
37
|
options: StreamListOptions<TInput, TItem>,
|
package/src/trace.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents parsed W3C trace context headers for router instrumentation.
|
|
3
|
+
*/
|
|
1
4
|
export interface RouterTraceContext {
|
|
2
5
|
parentSpanId: string;
|
|
3
6
|
sampled: boolean;
|
|
@@ -6,6 +9,9 @@ export interface RouterTraceContext {
|
|
|
6
9
|
tracestate?: string;
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Describes a router request lifecycle instrumentation event.
|
|
14
|
+
*/
|
|
9
15
|
export interface RouterRequestInstrumentationEvent {
|
|
10
16
|
method: string;
|
|
11
17
|
path: string;
|
|
@@ -13,32 +19,50 @@ export interface RouterRequestInstrumentationEvent {
|
|
|
13
19
|
trace?: RouterTraceContext;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Describes completion of a router request lifecycle event.
|
|
24
|
+
*/
|
|
16
25
|
export interface RouterRequestEndInstrumentationEvent
|
|
17
26
|
extends RouterRequestInstrumentationEvent {
|
|
18
27
|
status: number;
|
|
19
28
|
}
|
|
20
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Describes a route-level loader or render instrumentation event.
|
|
32
|
+
*/
|
|
21
33
|
export interface RouterRouteInstrumentationEvent
|
|
22
34
|
extends RouterRequestInstrumentationEvent {
|
|
23
35
|
routeId: string;
|
|
24
36
|
routePath: string;
|
|
25
37
|
}
|
|
26
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Describes completion of a route-level instrumentation event.
|
|
41
|
+
*/
|
|
27
42
|
export interface RouterRouteEndInstrumentationEvent
|
|
28
43
|
extends RouterRouteInstrumentationEvent {
|
|
29
44
|
error?: unknown;
|
|
30
45
|
}
|
|
31
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Describes a middleware instrumentation event.
|
|
49
|
+
*/
|
|
32
50
|
export interface RouterMiddlewareInstrumentationEvent
|
|
33
51
|
extends RouterRequestInstrumentationEvent {
|
|
34
52
|
name: string;
|
|
35
53
|
}
|
|
36
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Describes completion of a middleware instrumentation event.
|
|
57
|
+
*/
|
|
37
58
|
export interface RouterMiddlewareEndInstrumentationEvent
|
|
38
59
|
extends RouterMiddlewareInstrumentationEvent {
|
|
39
60
|
error?: unknown;
|
|
40
61
|
}
|
|
41
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Registers optional hooks for app-router request, middleware, and route instrumentation.
|
|
65
|
+
*/
|
|
42
66
|
export interface RouterInstrumentation {
|
|
43
67
|
onLoaderEnd?: (event: RouterRouteEndInstrumentationEvent) => void | Promise<void>;
|
|
44
68
|
onLoaderStart?: (event: RouterRouteInstrumentationEvent) => void | Promise<void>;
|
|
@@ -48,6 +72,9 @@ export interface RouterInstrumentation {
|
|
|
48
72
|
onRequestStart?: (event: RouterRequestInstrumentationEvent) => void | Promise<void>;
|
|
49
73
|
}
|
|
50
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Parses W3C trace context header values for router instrumentation.
|
|
77
|
+
*/
|
|
51
78
|
export function parseTraceContext(
|
|
52
79
|
traceparent: string | null | undefined,
|
|
53
80
|
tracestate: string | null | undefined,
|
|
@@ -81,6 +108,9 @@ export function parseTraceContext(
|
|
|
81
108
|
};
|
|
82
109
|
}
|
|
83
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Reads trace context headers from a request.
|
|
113
|
+
*/
|
|
84
114
|
export function traceContextFromRequest(request: Request): RouterTraceContext | undefined {
|
|
85
115
|
return parseTraceContext(request.headers.get("traceparent"), request.headers.get("tracestate"));
|
|
86
116
|
}
|