react-router 0.0.0-experimental-bcda00aaf → 0.0.0-experimental-3278f3ca6
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/CHANGELOG.md +0 -7
- package/README.md +1 -10
- package/dist/dom-export.d.ts +3 -0
- package/dist/dom-export.mjs +205 -0
- package/dist/dom-export.mjs.map +1 -0
- package/dist/index.d.ts +79 -29
- package/dist/index.mjs +11726 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/components.d.ts +249 -34
- package/dist/lib/context.d.ts +18 -5
- package/dist/lib/dom/dom.d.ts +123 -0
- package/dist/lib/dom/global.d.ts +40 -0
- package/dist/lib/dom/lib.d.ts +940 -0
- package/dist/lib/dom/server.d.ts +41 -0
- package/dist/lib/dom/ssr/components.d.ts +123 -0
- package/dist/lib/dom/ssr/data.d.ts +7 -0
- package/dist/lib/dom/ssr/entry.d.ts +47 -0
- package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
- package/dist/lib/dom/ssr/errors.d.ts +2 -0
- package/dist/lib/dom/ssr/fallback.d.ts +2 -0
- package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
- package/dist/lib/dom/ssr/invariant.d.ts +2 -0
- package/dist/lib/dom/ssr/links.d.ts +25 -0
- package/dist/lib/dom/ssr/markup.d.ts +5 -0
- package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
- package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
- package/dist/lib/dom/ssr/routes.d.ts +32 -0
- package/dist/lib/dom/ssr/server.d.ts +16 -0
- package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
- package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
- package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
- package/dist/lib/hooks.d.ts +284 -55
- package/dist/lib/router/history.d.ts +253 -0
- package/dist/lib/router/links.d.ts +104 -0
- package/dist/lib/router/router.d.ts +540 -0
- package/dist/lib/router/utils.d.ts +505 -0
- package/dist/lib/server-runtime/build.d.ts +38 -0
- package/dist/lib/server-runtime/cookies.d.ts +62 -0
- package/dist/lib/server-runtime/crypto.d.ts +2 -0
- package/dist/lib/server-runtime/data.d.ts +28 -0
- package/dist/lib/server-runtime/dev.d.ts +8 -0
- package/dist/lib/server-runtime/entry.d.ts +3 -0
- package/dist/lib/server-runtime/errors.d.ts +51 -0
- package/dist/lib/server-runtime/formData.d.ts +15 -0
- package/dist/lib/server-runtime/headers.d.ts +3 -0
- package/dist/lib/server-runtime/invariant.d.ts +2 -0
- package/dist/lib/server-runtime/jsonify.d.ts +33 -0
- package/dist/lib/server-runtime/markup.d.ts +1 -0
- package/dist/lib/server-runtime/mode.d.ts +9 -0
- package/dist/lib/server-runtime/responses.d.ts +37 -0
- package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
- package/dist/lib/server-runtime/routeModules.d.ts +212 -0
- package/dist/lib/server-runtime/routes.d.ts +31 -0
- package/dist/lib/server-runtime/server.d.ts +5 -0
- package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
- package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
- package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
- package/dist/lib/server-runtime/sessions.d.ts +140 -0
- package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
- package/dist/lib/server-runtime/typecheck.d.ts +4 -0
- package/dist/lib/server-runtime/upload/errors.d.ts +5 -0
- package/dist/lib/server-runtime/upload/memoryUploadHandler.d.ts +21 -0
- package/dist/lib/server-runtime/warnings.d.ts +1 -0
- package/dist/main-dom-export.js +19 -0
- package/dist/main.js +1 -1
- package/dist/react-router-dom.development.js +199 -0
- package/dist/react-router-dom.development.js.map +1 -0
- package/dist/react-router-dom.production.min.js +12 -0
- package/dist/react-router-dom.production.min.js.map +1 -0
- package/dist/react-router.development.js +12367 -1134
- package/dist/react-router.development.js.map +1 -1
- package/dist/react-router.production.min.js +2 -2
- package/dist/react-router.production.min.js.map +1 -1
- package/dist/umd/react-router-dom.development.js +241 -0
- package/dist/umd/react-router-dom.development.js.map +1 -0
- package/dist/umd/react-router-dom.production.min.js +12 -0
- package/dist/umd/react-router-dom.production.min.js.map +1 -0
- package/dist/umd/react-router.development.js +12691 -1284
- package/dist/umd/react-router.development.js.map +1 -1
- package/dist/umd/react-router.production.min.js +2 -2
- package/dist/umd/react-router.production.min.js.map +1 -1
- package/package.json +32 -6
- package/dist/index.js +0 -1471
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { StaticHandlerContext } from "../router/router";
|
|
2
|
+
import { ServerMode } from "./mode";
|
|
3
|
+
/**
|
|
4
|
+
* This thing probably warrants some explanation.
|
|
5
|
+
*
|
|
6
|
+
* The whole point here is to emulate componentDidCatch for server rendering and
|
|
7
|
+
* data loading. It can get tricky. React can do this on component boundaries
|
|
8
|
+
* but doesn't support it for server rendering or data loading. We know enough
|
|
9
|
+
* with nested routes to be able to emulate the behavior (because we know them
|
|
10
|
+
* statically before rendering.)
|
|
11
|
+
*
|
|
12
|
+
* Each route can export an `ErrorBoundary`.
|
|
13
|
+
*
|
|
14
|
+
* - When rendering throws an error, the nearest error boundary will render
|
|
15
|
+
* (normal react componentDidCatch). This will be the route's own boundary, but
|
|
16
|
+
* if none is provided, it will bubble up to the parents.
|
|
17
|
+
* - When data loading throws an error, the nearest error boundary will render
|
|
18
|
+
* - When performing an action, the nearest error boundary for the action's
|
|
19
|
+
* route tree will render (no redirect happens)
|
|
20
|
+
*
|
|
21
|
+
* During normal react rendering, we do nothing special, just normal
|
|
22
|
+
* componentDidCatch.
|
|
23
|
+
*
|
|
24
|
+
* For server rendering, we mutate `renderBoundaryRouteId` to know the last
|
|
25
|
+
* layout that has an error boundary that tried to render. This emulates which
|
|
26
|
+
* layout would catch a thrown error. If the rendering fails, we catch the error
|
|
27
|
+
* on the server, and go again a second time with the emulator holding on to the
|
|
28
|
+
* information it needs to render the same error boundary as a dynamically
|
|
29
|
+
* thrown render error.
|
|
30
|
+
*
|
|
31
|
+
* When data loading, server or client side, we use the emulator to likewise
|
|
32
|
+
* hang on to the error and re-render at the appropriate layout (where a thrown
|
|
33
|
+
* error would have been caught by cDC).
|
|
34
|
+
*
|
|
35
|
+
* When actions throw, it all works the same. There's an edge case to be aware
|
|
36
|
+
* of though. Actions normally are required to redirect, but in the case of
|
|
37
|
+
* errors, we render the action's route with the emulator holding on to the
|
|
38
|
+
* error. If during this render a parent route/loader throws we ignore that new
|
|
39
|
+
* error and render the action's original error as deeply as possible. In other
|
|
40
|
+
* words, we simply ignore the new error and use the action's error in place
|
|
41
|
+
* because it came first, and that just wouldn't be fair to let errors cut in
|
|
42
|
+
* line.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sanitizeError<T = unknown>(error: T, serverMode: ServerMode): Error | T;
|
|
45
|
+
export declare function sanitizeErrors(errors: NonNullable<StaticHandlerContext["errors"]>, serverMode: ServerMode): {};
|
|
46
|
+
export type SerializedError = {
|
|
47
|
+
message: string;
|
|
48
|
+
stack?: string;
|
|
49
|
+
};
|
|
50
|
+
export declare function serializeError(error: Error, serverMode: ServerMode): SerializedError;
|
|
51
|
+
export declare function serializeErrors(errors: StaticHandlerContext["errors"], serverMode: ServerMode): StaticHandlerContext["errors"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type UploadHandlerPart = {
|
|
2
|
+
name: string;
|
|
3
|
+
filename?: string;
|
|
4
|
+
contentType: string;
|
|
5
|
+
data: AsyncIterable<Uint8Array>;
|
|
6
|
+
};
|
|
7
|
+
export type UploadHandler = (part: UploadHandlerPart) => Promise<File | string | null | undefined>;
|
|
8
|
+
export declare function composeUploadHandlers(...handlers: UploadHandler[]): UploadHandler;
|
|
9
|
+
/**
|
|
10
|
+
* Allows you to handle multipart forms (file uploads) for your app.
|
|
11
|
+
*
|
|
12
|
+
* TODO: Update this comment
|
|
13
|
+
* @see https://remix.run/utils/parse-multipart-form-data
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseMultipartFormData(request: Request, uploadHandler: UploadHandler): Promise<FormData>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type Jsonify<T> = IsAny<T> extends true ? any : T extends {
|
|
2
|
+
toJSON(): infer U;
|
|
3
|
+
} ? (U extends JsonValue ? U : unknown) : T extends JsonPrimitive ? T : T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends Promise<unknown> ? EmptyObject : T extends Map<unknown, unknown> ? EmptyObject : T extends Set<unknown> ? EmptyObject : T extends TypedArray ? Record<string, number> : T extends NotJson ? never : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [NeverToNull<Jsonify<F>>, ...Jsonify<R>] : T extends readonly unknown[] ? Array<NeverToNull<Jsonify<T[number]>>> : T extends Record<keyof unknown, unknown> ? JsonifyObject<T> : unknown extends T ? unknown : never;
|
|
4
|
+
type ValueIsNotJson<T> = T extends NotJson ? true : false;
|
|
5
|
+
type IsNotJson<T> = {
|
|
6
|
+
[K in keyof T]-?: ValueIsNotJson<T[K]>;
|
|
7
|
+
};
|
|
8
|
+
type JsonifyValues<T> = {
|
|
9
|
+
[K in keyof T]: Jsonify<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
type JsonifyObject<T extends Record<keyof unknown, unknown>> = {
|
|
12
|
+
[K in keyof T as unknown extends T[K] ? never : IsNotJson<T>[K] extends false ? K : never]: JsonifyValues<T>[K];
|
|
13
|
+
} & {
|
|
14
|
+
[K in keyof T as unknown extends T[K] ? K : IsNotJson<T>[K] extends false ? never : IsNotJson<T>[K] extends true ? never : K]?: JsonifyValues<T>[K];
|
|
15
|
+
};
|
|
16
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
17
|
+
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
18
|
+
type JsonObject = {
|
|
19
|
+
[K in string]: JsonValue;
|
|
20
|
+
} & {
|
|
21
|
+
[K in string]?: JsonValue;
|
|
22
|
+
};
|
|
23
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
24
|
+
type NotJson = undefined | symbol | AnyFunction;
|
|
25
|
+
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
26
|
+
type AnyFunction = (...args: any[]) => unknown;
|
|
27
|
+
type NeverToNull<T> = [T] extends [never] ? null : T;
|
|
28
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
29
|
+
export type EmptyObject = {
|
|
30
|
+
[emptyObjectSymbol]?: never;
|
|
31
|
+
};
|
|
32
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHtml(html: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => TypedResponse<Data>;
|
|
2
|
+
export type TypedResponse<T = unknown> = Omit<Response, "json"> & {
|
|
3
|
+
json(): Promise<T>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* This is a shortcut for creating `application/json` responses. Converts `data`
|
|
7
|
+
* to JSON and sets the `Content-Type` header.
|
|
8
|
+
*
|
|
9
|
+
* @see https://remix.run/utils/json
|
|
10
|
+
*/
|
|
11
|
+
export declare const json: JsonFunction;
|
|
12
|
+
export type RedirectFunction = (url: string, init?: number | ResponseInit) => TypedResponse<never>;
|
|
13
|
+
/**
|
|
14
|
+
* A redirect response. Sets the status code and the `Location` header.
|
|
15
|
+
* Defaults to "302 Found".
|
|
16
|
+
*
|
|
17
|
+
* @see https://remix.run/utils/redirect
|
|
18
|
+
*/
|
|
19
|
+
export declare const redirect: RedirectFunction;
|
|
20
|
+
/**
|
|
21
|
+
* A redirect response that will force a document reload to the new location.
|
|
22
|
+
* Sets the status code and the `Location` header.
|
|
23
|
+
* Defaults to "302 Found".
|
|
24
|
+
*
|
|
25
|
+
* @see https://remix.run/utils/redirect
|
|
26
|
+
*/
|
|
27
|
+
export declare const redirectDocument: RedirectFunction;
|
|
28
|
+
/**
|
|
29
|
+
* A redirect response. Sets the status code and the `Location` header.
|
|
30
|
+
* Defaults to "302 Found".
|
|
31
|
+
*
|
|
32
|
+
* @see https://remix.run/utils/redirect
|
|
33
|
+
*/
|
|
34
|
+
export declare const replace: RedirectFunction;
|
|
35
|
+
export declare function isResponse(value: any): value is Response;
|
|
36
|
+
export declare function isRedirectStatusCode(statusCode: number): boolean;
|
|
37
|
+
export declare function isRedirectResponse(response: Response): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Params } from "../router/utils";
|
|
2
|
+
import type { ServerRoute } from "./routes";
|
|
3
|
+
export interface RouteMatch<Route> {
|
|
4
|
+
params: Params;
|
|
5
|
+
pathname: string;
|
|
6
|
+
route: Route;
|
|
7
|
+
}
|
|
8
|
+
export declare function matchServerRoutes(routes: ServerRoute[], pathname: string, basename?: string): RouteMatch<ServerRoute>[] | null;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Location } from "../router/history";
|
|
2
|
+
import type { ActionFunction as RRActionFunction, ActionFunctionArgs as RRActionFunctionArgs, AgnosticRouteMatch, LoaderFunction as RRLoaderFunction, LoaderFunctionArgs as RRLoaderFunctionArgs, Params } from "../router/utils";
|
|
3
|
+
import type { AppData, AppLoadContext } from "./data";
|
|
4
|
+
import type { SerializeFrom } from "../dom/ssr/components";
|
|
5
|
+
import type { LinkDescriptor } from "../router/links";
|
|
6
|
+
export interface RouteModules<RouteModule> {
|
|
7
|
+
[routeId: string]: RouteModule | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use `LoaderFunctionArgs`/`ActionFunctionArgs` instead
|
|
11
|
+
*/
|
|
12
|
+
export type DataFunctionArgs = RRActionFunctionArgs<AppLoadContext> & RRLoaderFunctionArgs<AppLoadContext> & {
|
|
13
|
+
context: AppLoadContext;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A function that handles data mutations for a route on the server
|
|
17
|
+
*/
|
|
18
|
+
export type ActionFunction = (args: ActionFunctionArgs) => ReturnType<RRActionFunction>;
|
|
19
|
+
/**
|
|
20
|
+
* Arguments passed to a route `action` function
|
|
21
|
+
*/
|
|
22
|
+
export type ActionFunctionArgs = RRActionFunctionArgs<AppLoadContext> & {
|
|
23
|
+
context: AppLoadContext;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A function that handles data mutations for a route on the client
|
|
27
|
+
* @private Public API is exported from @react-router/react
|
|
28
|
+
*/
|
|
29
|
+
type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<RRActionFunction>;
|
|
30
|
+
/**
|
|
31
|
+
* Arguments passed to a route `clientAction` function
|
|
32
|
+
* @private Public API is exported from @react-router/react
|
|
33
|
+
*/
|
|
34
|
+
export type ClientActionFunctionArgs = RRActionFunctionArgs<undefined> & {
|
|
35
|
+
serverAction: <T = AppData>() => Promise<SerializeFrom<T>>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A function that loads data for a route on the server
|
|
39
|
+
*/
|
|
40
|
+
export type LoaderFunction = (args: LoaderFunctionArgs) => ReturnType<RRLoaderFunction>;
|
|
41
|
+
/**
|
|
42
|
+
* Arguments passed to a route `loader` function
|
|
43
|
+
*/
|
|
44
|
+
export type LoaderFunctionArgs = RRLoaderFunctionArgs<AppLoadContext> & {
|
|
45
|
+
context: AppLoadContext;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* A function that loads data for a route on the client
|
|
49
|
+
* @private Public API is exported from @react-router/react
|
|
50
|
+
*/
|
|
51
|
+
type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<RRLoaderFunction>) & {
|
|
52
|
+
hydrate?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Arguments passed to a route `clientLoader` function
|
|
56
|
+
* @private Public API is exported from @react-router/react
|
|
57
|
+
*/
|
|
58
|
+
export type ClientLoaderFunctionArgs = RRLoaderFunctionArgs<undefined> & {
|
|
59
|
+
serverLoader: <T = AppData>() => Promise<SerializeFrom<T>>;
|
|
60
|
+
};
|
|
61
|
+
export type HeadersArgs = {
|
|
62
|
+
loaderHeaders: Headers;
|
|
63
|
+
parentHeaders: Headers;
|
|
64
|
+
actionHeaders: Headers;
|
|
65
|
+
errorHeaders: Headers | undefined;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A function that returns HTTP headers to be used for a route. These headers
|
|
69
|
+
* will be merged with (and take precedence over) headers from parent routes.
|
|
70
|
+
*/
|
|
71
|
+
export interface HeadersFunction {
|
|
72
|
+
(args: HeadersArgs): Headers | HeadersInit;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A function that defines `<link>` tags to be inserted into the `<head>` of
|
|
76
|
+
* the document on route transitions.
|
|
77
|
+
*/
|
|
78
|
+
export interface LinksFunction {
|
|
79
|
+
(): LinkDescriptor[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A function that returns an array of data objects to use for rendering
|
|
83
|
+
* metadata HTML tags in a route. These tags are not rendered on descendant
|
|
84
|
+
* routes in the route hierarchy. In other words, they will only be rendered on
|
|
85
|
+
* the route in which they are exported.
|
|
86
|
+
*
|
|
87
|
+
* @param Loader - The type of the current route's loader function
|
|
88
|
+
* @param MatchLoaders - Mapping from a parent route's filepath to its loader
|
|
89
|
+
* function type
|
|
90
|
+
*
|
|
91
|
+
* Note that parent route filepaths are relative to the `app/` directory.
|
|
92
|
+
*
|
|
93
|
+
* For example, if this meta function is for `/sales/customers/$customerId`:
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* // app/root.tsx
|
|
97
|
+
* const loader = () => {
|
|
98
|
+
* return json({ hello: "world" } as const)
|
|
99
|
+
* }
|
|
100
|
+
* export type Loader = typeof loader
|
|
101
|
+
*
|
|
102
|
+
* // app/routes/sales.tsx
|
|
103
|
+
* const loader = () => {
|
|
104
|
+
* return json({ salesCount: 1074 })
|
|
105
|
+
* }
|
|
106
|
+
* export type Loader = typeof loader
|
|
107
|
+
*
|
|
108
|
+
* // app/routes/sales/customers.tsx
|
|
109
|
+
* const loader = () => {
|
|
110
|
+
* return json({ customerCount: 74 })
|
|
111
|
+
* }
|
|
112
|
+
* export type Loader = typeof loader
|
|
113
|
+
*
|
|
114
|
+
* // app/routes/sales/customers/$customersId.tsx
|
|
115
|
+
* import type { Loader as RootLoader } from "../../../root"
|
|
116
|
+
* import type { Loader as SalesLoader } from "../../sales"
|
|
117
|
+
* import type { Loader as CustomersLoader } from "../../sales/customers"
|
|
118
|
+
*
|
|
119
|
+
* const loader = () => {
|
|
120
|
+
* return json({ name: "Customer name" })
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* const meta: MetaFunction<typeof loader, {
|
|
124
|
+
* "root": RootLoader,
|
|
125
|
+
* "routes/sales": SalesLoader,
|
|
126
|
+
* "routes/sales/customers": CustomersLoader,
|
|
127
|
+
* }> = ({ data, matches }) => {
|
|
128
|
+
* const { name } = data
|
|
129
|
+
* // ^? string
|
|
130
|
+
* const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
|
|
131
|
+
* // ^? number
|
|
132
|
+
* const { salesCount } = matches.find((match) => match.id === "routes/sales").data
|
|
133
|
+
* // ^? number
|
|
134
|
+
* const { hello } = matches.find((match) => match.id === "root").data
|
|
135
|
+
* // ^? "world"
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export interface ServerRuntimeMetaFunction<Loader extends LoaderFunction | unknown = unknown, ParentsLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> {
|
|
140
|
+
(args: ServerRuntimeMetaArgs<Loader, ParentsLoaders>): ServerRuntimeMetaDescriptor[];
|
|
141
|
+
}
|
|
142
|
+
interface ServerRuntimeMetaMatch<RouteId extends string = string, Loader extends LoaderFunction | unknown = unknown> {
|
|
143
|
+
id: RouteId;
|
|
144
|
+
pathname: AgnosticRouteMatch["pathname"];
|
|
145
|
+
data: Loader extends LoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
146
|
+
handle?: RouteHandle;
|
|
147
|
+
params: AgnosticRouteMatch["params"];
|
|
148
|
+
meta: ServerRuntimeMetaDescriptor[];
|
|
149
|
+
error?: unknown;
|
|
150
|
+
}
|
|
151
|
+
type ServerRuntimeMetaMatches<MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> = Array<{
|
|
152
|
+
[K in keyof MatchLoaders]: ServerRuntimeMetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
|
|
153
|
+
}[keyof MatchLoaders]>;
|
|
154
|
+
export interface ServerRuntimeMetaArgs<Loader extends LoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | unknown> = Record<string, unknown>> {
|
|
155
|
+
data: (Loader extends LoaderFunction ? SerializeFrom<Loader> : AppData) | undefined;
|
|
156
|
+
params: Params;
|
|
157
|
+
location: Location;
|
|
158
|
+
matches: ServerRuntimeMetaMatches<MatchLoaders>;
|
|
159
|
+
error?: unknown;
|
|
160
|
+
}
|
|
161
|
+
export type ServerRuntimeMetaDescriptor = {
|
|
162
|
+
charSet: "utf-8";
|
|
163
|
+
} | {
|
|
164
|
+
title: string;
|
|
165
|
+
} | {
|
|
166
|
+
name: string;
|
|
167
|
+
content: string;
|
|
168
|
+
} | {
|
|
169
|
+
property: string;
|
|
170
|
+
content: string;
|
|
171
|
+
} | {
|
|
172
|
+
httpEquiv: string;
|
|
173
|
+
content: string;
|
|
174
|
+
} | {
|
|
175
|
+
"script:ld+json": LdJsonObject;
|
|
176
|
+
} | {
|
|
177
|
+
tagName: "meta" | "link";
|
|
178
|
+
[name: string]: string;
|
|
179
|
+
} | {
|
|
180
|
+
[name: string]: unknown;
|
|
181
|
+
};
|
|
182
|
+
type LdJsonObject = {
|
|
183
|
+
[Key in string]: LdJsonValue;
|
|
184
|
+
} & {
|
|
185
|
+
[Key in string]?: LdJsonValue | undefined;
|
|
186
|
+
};
|
|
187
|
+
type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
|
|
188
|
+
type LdJsonPrimitive = string | number | boolean | null;
|
|
189
|
+
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
190
|
+
/**
|
|
191
|
+
* An arbitrary object that is associated with a route.
|
|
192
|
+
*/
|
|
193
|
+
export type RouteHandle = unknown;
|
|
194
|
+
export interface EntryRouteModule {
|
|
195
|
+
clientAction?: ClientActionFunction;
|
|
196
|
+
clientLoader?: ClientLoaderFunction;
|
|
197
|
+
ErrorBoundary?: any;
|
|
198
|
+
HydrateFallback?: any;
|
|
199
|
+
Layout?: any;
|
|
200
|
+
default: any;
|
|
201
|
+
handle?: RouteHandle;
|
|
202
|
+
links?: LinksFunction;
|
|
203
|
+
meta?: ServerRuntimeMetaFunction;
|
|
204
|
+
}
|
|
205
|
+
export interface ServerRouteModule extends EntryRouteModule {
|
|
206
|
+
action?: ActionFunction;
|
|
207
|
+
headers?: HeadersFunction | {
|
|
208
|
+
[name: string]: string;
|
|
209
|
+
};
|
|
210
|
+
loader?: LoaderFunction;
|
|
211
|
+
}
|
|
212
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AgnosticDataRouteObject } from "../router/utils";
|
|
2
|
+
import type { FutureConfig } from "../dom/ssr/entry";
|
|
3
|
+
import type { ServerRouteModule } from "./routeModules";
|
|
4
|
+
export interface RouteManifest<Route> {
|
|
5
|
+
[routeId: string]: Route;
|
|
6
|
+
}
|
|
7
|
+
export type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
|
|
8
|
+
export interface Route {
|
|
9
|
+
index?: boolean;
|
|
10
|
+
caseSensitive?: boolean;
|
|
11
|
+
id: string;
|
|
12
|
+
parentId?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EntryRoute extends Route {
|
|
16
|
+
hasAction: boolean;
|
|
17
|
+
hasLoader: boolean;
|
|
18
|
+
hasClientAction: boolean;
|
|
19
|
+
hasClientLoader: boolean;
|
|
20
|
+
hasErrorBoundary: boolean;
|
|
21
|
+
imports?: string[];
|
|
22
|
+
css?: string[];
|
|
23
|
+
module: string;
|
|
24
|
+
parentId?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ServerRoute extends Route {
|
|
27
|
+
children: ServerRoute[];
|
|
28
|
+
module: ServerRouteModule;
|
|
29
|
+
}
|
|
30
|
+
export declare function createRoutes(manifest: ServerRouteManifest, parentId?: string, routesByParentId?: Record<string, Omit<ServerRoute, "children">[]>): ServerRoute[];
|
|
31
|
+
export declare function createStaticHandlerDataRoutes(manifest: ServerRouteManifest, future: FutureConfig, parentId?: string, routesByParentId?: Record<string, Omit<ServerRoute, "children">[]>): AgnosticDataRouteObject[];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AppLoadContext } from "./data";
|
|
2
|
+
import type { ServerBuild } from "./build";
|
|
3
|
+
export type RequestHandler = (request: Request, loadContext?: AppLoadContext) => Promise<Response>;
|
|
4
|
+
export type CreateRequestHandlerFunction = (build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>), mode?: string) => RequestHandler;
|
|
5
|
+
export declare const createRequestHandler: CreateRequestHandlerFunction;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HydrationState } from "../router/router";
|
|
2
|
+
import type { FutureConfig } from "../dom/ssr/entry";
|
|
3
|
+
type ValidateShape<T, Shape> = T extends Shape ? Exclude<keyof T, keyof Shape> extends never ? T : never : never;
|
|
4
|
+
export declare function createServerHandoffString<T>(serverHandoff: {
|
|
5
|
+
state?: ValidateShape<T, HydrationState>;
|
|
6
|
+
criticalCss?: string;
|
|
7
|
+
basename: string | undefined;
|
|
8
|
+
future: FutureConfig;
|
|
9
|
+
isSpaMode: boolean;
|
|
10
|
+
}): string;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SessionStorage, SessionIdStorageStrategy, SessionData } from "../sessions";
|
|
2
|
+
interface CookieSessionStorageOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The Cookie used to store the session data on the client, or options used
|
|
5
|
+
* to automatically create one.
|
|
6
|
+
*/
|
|
7
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates and returns a SessionStorage object that stores all session data
|
|
11
|
+
* directly in the session cookie itself.
|
|
12
|
+
*
|
|
13
|
+
* This has the advantage that no database or other backend services are
|
|
14
|
+
* needed, and can help to simplify some load-balanced scenarios. However, it
|
|
15
|
+
* also has the limitation that serialized session data may not exceed the
|
|
16
|
+
* browser's maximum cookie size. Trade-offs!
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SessionData, SessionStorage, SessionIdStorageStrategy } from "../sessions";
|
|
2
|
+
interface MemorySessionStorageOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The Cookie used to store the session id on the client, or options used
|
|
5
|
+
* to automatically create one.
|
|
6
|
+
*/
|
|
7
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates and returns a simple in-memory SessionStorage object, mostly useful
|
|
11
|
+
* for testing and as a reference implementation.
|
|
12
|
+
*
|
|
13
|
+
* Note: This storage does not scale beyond a single process, so it is not
|
|
14
|
+
* suitable for most production scenarios.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { CookieParseOptions, CookieSerializeOptions } from "cookie";
|
|
2
|
+
import type { Cookie, CookieOptions } from "./cookies";
|
|
3
|
+
/**
|
|
4
|
+
* An object of name/value pairs to be used in the session.
|
|
5
|
+
*/
|
|
6
|
+
export interface SessionData {
|
|
7
|
+
[name: string]: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Session persists data across HTTP requests.
|
|
11
|
+
*
|
|
12
|
+
* @see https://remix.run/utils/sessions#session-api
|
|
13
|
+
*/
|
|
14
|
+
export interface Session<Data = SessionData, FlashData = Data> {
|
|
15
|
+
/**
|
|
16
|
+
* A unique identifier for this session.
|
|
17
|
+
*
|
|
18
|
+
* Note: This will be the empty string for newly created sessions and
|
|
19
|
+
* sessions that are not backed by a database (i.e. cookie-based sessions).
|
|
20
|
+
*/
|
|
21
|
+
readonly id: string;
|
|
22
|
+
/**
|
|
23
|
+
* The raw data contained in this session.
|
|
24
|
+
*
|
|
25
|
+
* This is useful mostly for SessionStorage internally to access the raw
|
|
26
|
+
* session data to persist.
|
|
27
|
+
*/
|
|
28
|
+
readonly data: FlashSessionData<Data, FlashData>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns `true` if the session has a value for the given `name`, `false`
|
|
31
|
+
* otherwise.
|
|
32
|
+
*/
|
|
33
|
+
has(name: (keyof Data | keyof FlashData) & string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the value for the given `name` in this session.
|
|
36
|
+
*/
|
|
37
|
+
get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Sets a value in the session for the given `name`.
|
|
40
|
+
*/
|
|
41
|
+
set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
|
|
42
|
+
/**
|
|
43
|
+
* Sets a value in the session that is only valid until the next `get()`.
|
|
44
|
+
* This can be useful for temporary values, like error messages.
|
|
45
|
+
*/
|
|
46
|
+
flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Removes a value from the session.
|
|
49
|
+
*/
|
|
50
|
+
unset(name: keyof Data & string): void;
|
|
51
|
+
}
|
|
52
|
+
export type FlashSessionData<Data, FlashData> = Partial<Data & {
|
|
53
|
+
[Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
|
|
54
|
+
}>;
|
|
55
|
+
type FlashDataKey<Key extends string> = `__flash_${Key}__`;
|
|
56
|
+
export type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new Session object.
|
|
59
|
+
*
|
|
60
|
+
* Note: This function is typically not invoked directly by application code.
|
|
61
|
+
* Instead, use a `SessionStorage` object's `getSession` method.
|
|
62
|
+
*
|
|
63
|
+
* @see https://remix.run/utils/sessions#createsession
|
|
64
|
+
*/
|
|
65
|
+
export declare const createSession: CreateSessionFunction;
|
|
66
|
+
export type IsSessionFunction = (object: any) => object is Session;
|
|
67
|
+
/**
|
|
68
|
+
* Returns true if an object is a Remix session.
|
|
69
|
+
*
|
|
70
|
+
* @see https://remix.run/utils/sessions#issession
|
|
71
|
+
*/
|
|
72
|
+
export declare const isSession: IsSessionFunction;
|
|
73
|
+
/**
|
|
74
|
+
* SessionStorage stores session data between HTTP requests and knows how to
|
|
75
|
+
* parse and create cookies.
|
|
76
|
+
*
|
|
77
|
+
* A SessionStorage creates Session objects using a `Cookie` header as input.
|
|
78
|
+
* Then, later it generates the `Set-Cookie` header to be used in the response.
|
|
79
|
+
*/
|
|
80
|
+
export interface SessionStorage<Data = SessionData, FlashData = Data> {
|
|
81
|
+
/**
|
|
82
|
+
* Parses a Cookie header from a HTTP request and returns the associated
|
|
83
|
+
* Session. If there is no session associated with the cookie, this will
|
|
84
|
+
* return a new Session with no data.
|
|
85
|
+
*/
|
|
86
|
+
getSession: (cookieHeader?: string | null, options?: CookieParseOptions) => Promise<Session<Data, FlashData>>;
|
|
87
|
+
/**
|
|
88
|
+
* Stores all data in the Session and returns the Set-Cookie header to be
|
|
89
|
+
* used in the HTTP response.
|
|
90
|
+
*/
|
|
91
|
+
commitSession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Deletes all data associated with the Session and returns the Set-Cookie
|
|
94
|
+
* header to be used in the HTTP response.
|
|
95
|
+
*/
|
|
96
|
+
destroySession: (session: Session<Data, FlashData>, options?: CookieSerializeOptions) => Promise<string>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* SessionIdStorageStrategy is designed to allow anyone to easily build their
|
|
100
|
+
* own SessionStorage using `createSessionStorage(strategy)`.
|
|
101
|
+
*
|
|
102
|
+
* This strategy describes a common scenario where the session id is stored in
|
|
103
|
+
* a cookie but the actual session data is stored elsewhere, usually in a
|
|
104
|
+
* database or on disk. A set of create, read, update, and delete operations
|
|
105
|
+
* are provided for managing the session data.
|
|
106
|
+
*/
|
|
107
|
+
export interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
|
|
108
|
+
/**
|
|
109
|
+
* The Cookie used to store the session id, or options used to automatically
|
|
110
|
+
* create one.
|
|
111
|
+
*/
|
|
112
|
+
cookie?: Cookie | (CookieOptions & {
|
|
113
|
+
name?: string;
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* Creates a new record with the given data and returns the session id.
|
|
117
|
+
*/
|
|
118
|
+
createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns data for a given session id, or `null` if there isn't any.
|
|
121
|
+
*/
|
|
122
|
+
readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Updates data for the given session id.
|
|
125
|
+
*/
|
|
126
|
+
updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Deletes data for a given session id from the data store.
|
|
129
|
+
*/
|
|
130
|
+
deleteData: (id: string) => Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates a SessionStorage object using a SessionIdStorageStrategy.
|
|
134
|
+
*
|
|
135
|
+
* Note: This is a low-level API that should only be used if none of the
|
|
136
|
+
* existing session storage options meet your requirements.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
|
|
139
|
+
export declare function warnOnceAboutSigningSessionCookie(cookie: Cookie): void;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { StaticHandler } from "../router/router";
|
|
2
|
+
import type { DataStrategyFunction } from "../router/utils";
|
|
3
|
+
import type { SingleFetchRedirectResult, SingleFetchResult, SingleFetchResults } from "../dom/ssr/single-fetch";
|
|
4
|
+
import { SingleFetchRedirectSymbol } from "../dom/ssr/single-fetch";
|
|
5
|
+
import type { AppLoadContext } from "./data";
|
|
6
|
+
import { ServerMode } from "./mode";
|
|
7
|
+
import type { ServerBuild } from "./build";
|
|
8
|
+
export type { SingleFetchResult, SingleFetchResults };
|
|
9
|
+
export { SingleFetchRedirectSymbol };
|
|
10
|
+
export declare const SINGLE_FETCH_REDIRECT_STATUS = 202;
|
|
11
|
+
export declare function getSingleFetchDataStrategy({ isActionDataRequest, loadRouteIds, }?: {
|
|
12
|
+
isActionDataRequest?: boolean;
|
|
13
|
+
loadRouteIds?: string[];
|
|
14
|
+
}): DataStrategyFunction;
|
|
15
|
+
export declare function singleFetchAction(build: ServerBuild, serverMode: ServerMode, staticHandler: StaticHandler, request: Request, handlerUrl: URL, loadContext: AppLoadContext, handleError: (err: unknown) => void): Promise<{
|
|
16
|
+
result: SingleFetchResult;
|
|
17
|
+
headers: Headers;
|
|
18
|
+
status: number;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function singleFetchLoaders(build: ServerBuild, serverMode: ServerMode, staticHandler: StaticHandler, request: Request, handlerUrl: URL, loadContext: AppLoadContext, handleError: (err: unknown) => void): Promise<{
|
|
21
|
+
result: SingleFetchResults;
|
|
22
|
+
headers: Headers;
|
|
23
|
+
status: number;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function getSingleFetchRedirect(status: number, headers: Headers, basename: string | undefined): SingleFetchRedirectResult;
|
|
26
|
+
type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
|
|
27
|
+
[key: PropertyKey]: Serializable;
|
|
28
|
+
} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
|
|
29
|
+
export declare function data(value: Serializable, init?: number | ResponseInit): import("../router/utils").DataWithResponseInit<Serializable>;
|
|
30
|
+
export declare function encodeViaTurboStream(data: any, requestSignal: AbortSignal, streamTimeout: number | undefined, serverMode: ServerMode): ReadableStream<Uint8Array>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function expectType<T>(_expression: T): void;
|
|
2
|
+
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
3
|
+
export type Expect<T extends true> = T;
|
|
4
|
+
export type MutualExtends<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
|