react-router 6.26.2 → 7.0.0-pre.0
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 +307 -0
- package/README.md +1 -14
- 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 +74 -29
- package/dist/index.mjs +11551 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/components.d.ts +250 -35
- package/dist/lib/context.d.ts +20 -7
- 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/dom-export.d.ts +3 -0
- package/dist/lib/hooks.d.ts +286 -57
- 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 +15 -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/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/warnings.d.ts +1 -0
- package/dist/lib/types.d.ts +71 -0
- package/dist/lib/types.mjs +10 -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 +12271 -1129
- 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 +12459 -1224
- 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 +35 -6
- package/dist/index.js +0 -1467
- package/dist/index.js.map +0 -1
|
@@ -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
|
+
export 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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warnOnce(condition: boolean, message: string): void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AppLoadContext } from "./server-runtime/data";
|
|
2
|
+
import type { Serializable } from "./server-runtime/single-fetch";
|
|
3
|
+
export type Expect<T extends true> = T;
|
|
4
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
5
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
6
|
+
type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
|
|
7
|
+
type Fn = (...args: any[]) => unknown;
|
|
8
|
+
type RouteModule = {
|
|
9
|
+
loader?: Fn;
|
|
10
|
+
clientLoader?: Fn;
|
|
11
|
+
action?: Fn;
|
|
12
|
+
clientAction?: Fn;
|
|
13
|
+
HydrateFallback?: unknown;
|
|
14
|
+
default?: unknown;
|
|
15
|
+
ErrorBoundary?: unknown;
|
|
16
|
+
};
|
|
17
|
+
type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
|
|
18
|
+
type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Fn ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
|
|
19
|
+
type ServerDataFrom<T> = Serialize<DataFrom<T>>;
|
|
20
|
+
type ClientDataFrom<T> = DataFrom<T>;
|
|
21
|
+
type IsHydrate<ClientLoader> = ClientLoader extends {
|
|
22
|
+
hydrate: true;
|
|
23
|
+
} ? true : ClientLoader extends {
|
|
24
|
+
hydrate: false;
|
|
25
|
+
} ? false : false;
|
|
26
|
+
export type CreateLoaderData<T extends RouteModule> = _CreateLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
|
|
27
|
+
HydrateFallback: Fn;
|
|
28
|
+
} ? true : false>;
|
|
29
|
+
type _CreateLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
|
|
30
|
+
HasHydrateFallback,
|
|
31
|
+
ClientLoaderHydrate
|
|
32
|
+
] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
|
|
33
|
+
IsDefined<ClientLoaderData>,
|
|
34
|
+
IsDefined<ServerLoaderData>
|
|
35
|
+
] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderHydrate extends true ? ClientLoaderData : ClientLoaderData | undefined : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
|
|
36
|
+
export type CreateActionData<T extends RouteModule> = _CreateActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
|
|
37
|
+
type _CreateActionData<ServerActionData, ClientActionData> = Awaited<[
|
|
38
|
+
IsDefined<ServerActionData>,
|
|
39
|
+
IsDefined<ClientActionData>
|
|
40
|
+
] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
|
|
41
|
+
type DataFunctionArgs<Params> = {
|
|
42
|
+
request: Request;
|
|
43
|
+
params: Params;
|
|
44
|
+
context?: AppLoadContext;
|
|
45
|
+
};
|
|
46
|
+
type Serialize<T> = T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
|
|
47
|
+
[K in keyof T]: Serialize<T[K]>;
|
|
48
|
+
} : undefined;
|
|
49
|
+
export type CreateServerLoaderArgs<Params> = DataFunctionArgs<Params>;
|
|
50
|
+
export type CreateClientLoaderArgs<Params, T extends RouteModule> = DataFunctionArgs<Params> & {
|
|
51
|
+
serverLoader: () => Promise<ServerDataFrom<T["loader"]>>;
|
|
52
|
+
};
|
|
53
|
+
export type CreateServerActionArgs<Params> = DataFunctionArgs<Params>;
|
|
54
|
+
export type CreateClientActionArgs<Params, T extends RouteModule> = DataFunctionArgs<Params> & {
|
|
55
|
+
serverAction: () => Promise<ServerDataFrom<T["action"]>>;
|
|
56
|
+
};
|
|
57
|
+
export type CreateHydrateFallbackProps<Params> = {
|
|
58
|
+
params: Params;
|
|
59
|
+
};
|
|
60
|
+
export type CreateComponentProps<Params, LoaderData, ActionData> = {
|
|
61
|
+
params: Params;
|
|
62
|
+
loaderData: LoaderData;
|
|
63
|
+
actionData?: ActionData;
|
|
64
|
+
};
|
|
65
|
+
export type CreateErrorBoundaryProps<Params, LoaderData, ActionData> = {
|
|
66
|
+
params: Params;
|
|
67
|
+
error: unknown;
|
|
68
|
+
loaderData?: LoaderData;
|
|
69
|
+
actionData?: ActionData;
|
|
70
|
+
};
|
|
71
|
+
export {};
|