UNPKG

33.6 kBTypeScriptView Raw
1import { R as RouteModules, a as Router, D as DataStrategyFunction, A as ActionFunction, L as LoaderFunction, C as ClientActionFunction, b as ClientLoaderFunction, c as LinksFunction, M as MetaFunction, d as RouteManifest, e as LoaderFunctionArgs, f as ActionFunctionArgs, T as To, g as RelativeRoutingType, h as Location, i as Action, P as ParamParseKey, j as Path, k as PathPattern, l as PathMatch, N as NavigateOptions, m as Params, n as RouteObject, o as Navigation, p as RevalidationState, U as UIMatch, S as SerializeFrom, B as BlockerFunction, q as Blocker, r as StaticHandlerContext, s as StaticHandler, F as FutureConfig$1, t as CreateStaticHandlerOptions$1, I as InitialEntry, H as HydrationState, u as IndexRouteObject, v as NonIndexRouteObject, w as RouterState } from './route-data-aSUFWnQ6.js';
2export { ap as ClientActionFunctionArgs, aq as ClientLoaderFunctionArgs, aj as DataRouteMatch, ak as DataRouteObject, Q as DataStrategyFunctionArgs, V as DataStrategyMatch, W as DataStrategyResult, Y as ErrorResponse, y as Fetcher, Z as FormEncType, _ as FormMethod, G as GetScrollPositionFunction, x as GetScrollRestorationKeyFunction, $ as HTMLFormMethod, au as HtmlLinkDescriptor, a9 as IDLE_BLOCKER, a8 as IDLE_FETCHER, a7 as IDLE_NAVIGATION, a0 as LazyRouteFunction, av as LinkDescriptor, ar as MetaArgs, as as MetaDescriptor, z as NavigationStates, al as Navigator, at as PageLinkDescriptor, am as PatchRoutesOnNavigationFunction, an as PatchRoutesOnNavigationFunctionArgs, a1 as PathParam, a2 as RedirectFunction, ao as RouteMatch, O as RouterFetchOptions, E as RouterInit, K as RouterNavigateOptions, J as RouterSubscriber, a3 as ShouldRevalidateFunction, a4 as ShouldRevalidateFunctionArgs, aA as UNSAFE_DataRouterContext, aB as UNSAFE_DataRouterStateContext, X as UNSAFE_DataWithResponseInit, az as UNSAFE_ErrorResponseImpl, aC as UNSAFE_FetchersContext, aD as UNSAFE_LocationContext, aE as UNSAFE_NavigationContext, aF as UNSAFE_RouteContext, aG as UNSAFE_ViewTransitionContext, aw as UNSAFE_createBrowserHistory, ay as UNSAFE_createRouter, ax as UNSAFE_invariant, a5 as createPath, aa as data, ab as generatePath, ac as isRouteErrorResponse, ad as matchPath, ae as matchRoutes, a6 as parsePath, af as redirect, ag as redirectDocument, ah as replace, ai as resolvePath } from './route-data-aSUFWnQ6.js';
3import { A as AssetsManifest, a as Route, F as FutureConfig, E as EntryContext } from './fog-of-war-DLtn2OLr.js';
4export { f as Await, b as AwaitProps, J as BrowserRouter, B as BrowserRouterProps, v as FetcherFormProps, z as FetcherSubmitFunction, a4 as FetcherSubmitOptions, C as FetcherWithComponents, V as Form, w as FormProps, K as HashRouter, H as HashRouterProps, q as HistoryRouterProps, I as IndexRouteProps, L as LayoutRouteProps, Q as Link, s as LinkProps, ab as Links, g as MemoryRouter, M as MemoryRouterProps, aa as Meta, U as NavLink, t as NavLinkProps, u as NavLinkRenderProps, h as Navigate, N as NavigateProps, i as Outlet, O as OutletProps, a5 as ParamKeyValuePair, P as PathRouteProps, ad as PrefetchPageLinks, j as Route, c as RouteProps, k as Router, d as RouterProps, l as RouterProvider, R as RouterProviderProps, m as Routes, e as RoutesProps, ac as Scripts, ae as ScriptsProps, W as ScrollRestoration, S as ScrollRestorationProps, x as SetURLSearchParams, y as SubmitFunction, a6 as SubmitOptions, a8 as SubmitTarget, ag as UNSAFE_FrameworkContext, aj as UNSAFE_createClientRoutes, ak as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, ah as UNSAFE_getPatchRoutesOnNavigationFunction, af as UNSAFE_mapRouteProperties, al as UNSAFE_shouldHydrateRouteLoader, ai as UNSAFE_useFogOFWarDiscovery, am as UNSAFE_useScrollRestoration, a7 as URLSearchParamsInit, D as createBrowserRouter, G as createHashRouter, n as createMemoryRouter, o as createRoutesFromChildren, p as createRoutesFromElements, a9 as createSearchParams, r as renderMatches, T as unstable_HistoryRouter, a2 as unstable_usePrompt, a1 as useBeforeUnload, $ as useFetcher, a0 as useFetchers, _ as useFormAction, X as useLinkClickHandler, Y as useSearchParams, Z as useSubmit, a3 as useViewTransitionState } from './fog-of-war-DLtn2OLr.js';
5import * as React from 'react';
6import { ReactElement } from 'react';
7import { ParseOptions, SerializeOptions } from 'cookie';
8export { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions } from 'cookie';
9import { A as AppLoadContext$1 } from './data-CQbyyGzl.js';
10
11declare const SingleFetchRedirectSymbol: unique symbol;
12declare function getSingleFetchDataStrategy(manifest: AssetsManifest, routeModules: RouteModules, getRouter: () => Router): DataStrategyFunction;
13declare function decodeViaTurboStream(body: ReadableStream<Uint8Array>, global: Window | typeof globalThis): Promise<{
14 done: Promise<undefined>;
15 value: unknown;
16}>;
17
18/**
19 * The mode to use when running the server.
20 */
21declare enum ServerMode {
22 Development = "development",
23 Production = "production",
24 Test = "test"
25}
26
27type HeadersArgs = {
28 loaderHeaders: Headers;
29 parentHeaders: Headers;
30 actionHeaders: Headers;
31 errorHeaders: Headers | undefined;
32};
33/**
34 * A function that returns HTTP headers to be used for a route. These headers
35 * will be merged with (and take precedence over) headers from parent routes.
36 */
37interface HeadersFunction {
38 (args: HeadersArgs): Headers | HeadersInit;
39}
40/**
41 * An arbitrary object that is associated with a route.
42 */
43type RouteHandle = unknown;
44interface EntryRouteModule {
45 clientAction?: ClientActionFunction;
46 clientLoader?: ClientLoaderFunction;
47 ErrorBoundary?: any;
48 HydrateFallback?: any;
49 Layout?: any;
50 default: any;
51 handle?: RouteHandle;
52 links?: LinksFunction;
53 meta?: MetaFunction;
54}
55interface ServerRouteModule extends EntryRouteModule {
56 action?: ActionFunction;
57 headers?: HeadersFunction | {
58 [name: string]: string;
59 };
60 loader?: LoaderFunction;
61}
62
63type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
64interface ServerRoute extends Route {
65 children: ServerRoute[];
66 module: ServerRouteModule;
67}
68
69/**
70 * The output of the compiler for the server build.
71 */
72interface ServerBuild {
73 entry: {
74 module: ServerEntryModule;
75 };
76 routes: ServerRouteManifest;
77 assets: AssetsManifest;
78 basename?: string;
79 publicPath: string;
80 assetsBuildDirectory: string;
81 future: FutureConfig;
82 isSpaMode: boolean;
83}
84interface HandleDocumentRequestFunction {
85 (request: Request, responseStatusCode: number, responseHeaders: Headers, context: EntryContext, loadContext: AppLoadContext$1): Promise<Response> | Response;
86}
87interface HandleDataRequestFunction {
88 (response: Response, args: LoaderFunctionArgs | ActionFunctionArgs): Promise<Response> | Response;
89}
90interface HandleErrorFunction {
91 (error: unknown, args: LoaderFunctionArgs | ActionFunctionArgs): void;
92}
93/**
94 * A module that serves as the entry point for a Remix app during server
95 * rendering.
96 */
97interface ServerEntryModule {
98 default: HandleDocumentRequestFunction;
99 handleDataRequest?: HandleDataRequestFunction;
100 handleError?: HandleErrorFunction;
101 streamTimeout?: number;
102}
103
104/**
105 Resolves a URL against the current location.
106
107 ```tsx
108 import { useHref } from "react-router"
109
110 function SomeComponent() {
111 let href = useHref("some/where");
112 // "/resolved/some/where"
113 }
114 ```
115
116 @category Hooks
117 */
118declare function useHref(to: To, { relative }?: {
119 relative?: RelativeRoutingType;
120}): string;
121/**
122 * Returns true if this component is a descendant of a Router, useful to ensure
123 * a component is used within a Router.
124 *
125 * @category Hooks
126 */
127declare function useInRouterContext(): boolean;
128/**
129 Returns the current {@link Location}. This can be useful if you'd like to perform some side effect whenever it changes.
130
131 ```tsx
132 import * as React from 'react'
133 import { useLocation } from 'react-router'
134
135 function SomeComponent() {
136 let location = useLocation()
137
138 React.useEffect(() => {
139 // Google Analytics
140 ga('send', 'pageview')
141 }, [location]);
142
143 return (
144 // ...
145 );
146 }
147 ```
148
149 @category Hooks
150 */
151declare function useLocation(): Location;
152/**
153 * Returns the current navigation action which describes how the router came to
154 * the current location, either by a pop, push, or replace on the history stack.
155 *
156 * @category Hooks
157 */
158declare function useNavigationType(): Action;
159/**
160 * Returns a PathMatch object if the given pattern matches the current URL.
161 * This is useful for components that need to know "active" state, e.g.
162 * `<NavLink>`.
163 *
164 * @category Hooks
165 */
166declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
167/**
168 * The interface for the navigate() function returned from useNavigate().
169 */
170interface NavigateFunction {
171 (to: To, options?: NavigateOptions): void | Promise<void>;
172 (delta: number): void | Promise<void>;
173}
174/**
175 Returns a function that lets you navigate programmatically in the browser in response to user interactions or effects.
176
177 ```tsx
178 import { useNavigate } from "react-router";
179
180 function SomeComponent() {
181 let navigate = useNavigate();
182 return (
183 <button
184 onClick={() => {
185 navigate(-1);
186 }}
187 />
188 );
189 }
190 ```
191
192 It's often better to use {@link redirect} in {@link ActionFunction | actions} and {@link LoaderFunction | loaders} than this hook.
193
194 @category Hooks
195 */
196declare function useNavigate(): NavigateFunction;
197/**
198 * Returns the parent route {@link OutletProps.context | `<Outlet context>`}.
199 *
200 * @category Hooks
201 */
202declare function useOutletContext<Context = unknown>(): Context;
203/**
204 * Returns the element for the child route at this level of the route
205 * hierarchy. Used internally by `<Outlet>` to render child routes.
206 *
207 * @category Hooks
208 */
209declare function useOutlet(context?: unknown): React.ReactElement | null;
210/**
211 Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.
212
213 ```tsx
214 import { useParams } from "react-router"
215
216 function SomeComponent() {
217 let params = useParams()
218 params.postId
219 }
220 ```
221
222 Assuming a route pattern like `/posts/:postId` is matched by `/posts/123` then `params.postId` will be `"123"`.
223
224 @category Hooks
225 */
226declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
227 ParamsOrKey
228] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
229/**
230 Resolves the pathname of the given `to` value against the current location. Similar to {@link useHref}, but returns a {@link Path} instead of a string.
231
232 ```tsx
233 import { useResolvedPath } from "react-router"
234
235 function SomeComponent() {
236 // if the user is at /dashboard/profile
237 let path = useResolvedPath("../accounts")
238 path.pathname // "/dashboard/accounts"
239 path.search // ""
240 path.hash // ""
241 }
242 ```
243
244 @category Hooks
245 */
246declare function useResolvedPath(to: To, { relative }?: {
247 relative?: RelativeRoutingType;
248}): Path;
249/**
250 Hook version of {@link Routes | `<Routes>`} that uses objects instead of components. These objects have the same properties as the component props.
251
252 The return value of `useRoutes` is either a valid React element you can use to render the route tree, or `null` if nothing matched.
253
254 ```tsx
255 import * as React from "react";
256 import { useRoutes } from "react-router";
257
258 function App() {
259 let element = useRoutes([
260 {
261 path: "/",
262 element: <Dashboard />,
263 children: [
264 {
265 path: "messages",
266 element: <DashboardMessages />,
267 },
268 { path: "tasks", element: <DashboardTasks /> },
269 ],
270 },
271 { path: "team", element: <AboutPage /> },
272 ]);
273
274 return element;
275 }
276 ```
277
278 @category Hooks
279 */
280declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
281/**
282 Returns the current navigation, defaulting to an "idle" navigation when no navigation is in progress. You can use this to render pending UI (like a global spinner) or read FormData from a form navigation.
283
284 ```tsx
285 import { useNavigation } from "react-router"
286
287 function SomeComponent() {
288 let navigation = useNavigation();
289 navigation.state
290 navigation.formData
291 // etc.
292 }
293 ```
294
295 @category Hooks
296 */
297declare function useNavigation(): Navigation;
298/**
299 Revalidate the data on the page for reasons outside of normal data mutations like window focus or polling on an interval.
300
301 ```tsx
302 import { useRevalidator } from "react-router";
303
304 function WindowFocusRevalidator() {
305 const revalidator = useRevalidator();
306
307 useFakeWindowFocus(() => {
308 revalidator.revalidate();
309 });
310
311 return (
312 <div hidden={revalidator.state === "idle"}>
313 Revalidating...
314 </div>
315 );
316 }
317 ```
318
319 Note that page data is already revalidated automatically after actions. If you find yourself using this for normal CRUD operations on your data in response to user interactions, you're probably not taking advantage of the other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do this automatically.
320
321 @category Hooks
322 */
323declare function useRevalidator(): {
324 revalidate(): Promise<void>;
325 state: RevalidationState;
326};
327/**
328 * Returns the active route matches, useful for accessing loaderData for
329 * parent/child routes or the route "handle" property
330 *
331 * @category Hooks
332 */
333declare function useMatches(): UIMatch[];
334/**
335 Returns the data from the closest route {@link LoaderFunction | loader} or {@link ClientLoaderFunction | client loader}.
336
337 ```tsx
338 import { useLoaderData } from "react-router"
339
340 export async function loader() {
341 return await fakeDb.invoices.findAll();
342 }
343
344 export default function Invoices() {
345 let invoices = useLoaderData<typeof loader>();
346 // ...
347 }
348 ```
349
350 @category Hooks
351 */
352declare function useLoaderData<T = any>(): SerializeFrom<T>;
353/**
354 Returns the loader data for a given route by route ID.
355
356 ```tsx
357 import { useRouteLoaderData } from "react-router";
358
359 function SomeComponent() {
360 const { user } = useRouteLoaderData("root");
361 }
362 ```
363
364 Route IDs are created automatically. They are simply the path of the route file relative to the app folder without the extension.
365
366 | Route Filename | Route ID |
367 | -------------------------- | -------------------- |
368 | `app/root.tsx` | `"root"` |
369 | `app/routes/teams.tsx` | `"routes/teams"` |
370 | `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
371
372 If you created an ID manually, you can use that instead:
373
374 ```tsx
375 route("/", "containers/app.tsx", { id: "app" }})
376 ```
377
378 @category Hooks
379 */
380declare function useRouteLoaderData<T = any>(routeId: string): SerializeFrom<T> | undefined;
381/**
382 Returns the action data from the most recent POST navigation form submission or `undefined` if there hasn't been one.
383
384 ```tsx
385 import { Form, useActionData } from "react-router"
386
387 export async function action({ request }) {
388 const body = await request.formData()
389 const name = body.get("visitorsName")
390 return { message: `Hello, ${name}` }
391 }
392
393 export default function Invoices() {
394 const data = useActionData()
395 return (
396 <Form method="post">
397 <input type="text" name="visitorsName" />
398 {data ? data.message : "Waiting..."}
399 </Form>
400 )
401 }
402 ```
403
404 @category Hooks
405 */
406declare function useActionData<T = any>(): SerializeFrom<T> | undefined;
407/**
408 Accesses the error thrown during an {@link ActionFunction | action}, {@link LoaderFunction | loader}, or component render to be used in a route module Error Boundary.
409
410 ```tsx
411 export function ErrorBoundary() {
412 const error = useRouteError();
413 return <div>{error.message}</div>;
414 }
415 ```
416
417 @category Hooks
418 */
419declare function useRouteError(): unknown;
420/**
421 Returns the resolved promise value from the closest {@link Await | `<Await>`}.
422
423 ```tsx
424 function SomeDescendant() {
425 const value = useAsyncValue();
426 // ...
427 }
428
429 // somewhere in your app
430 <Await resolve={somePromise}>
431 <SomeDescendant />
432 </Await>
433 ```
434
435 @category Hooks
436 */
437declare function useAsyncValue(): unknown;
438/**
439 Returns the rejection value from the closest {@link Await | `<Await>`}.
440
441 ```tsx
442 import { Await, useAsyncError } from "react-router"
443
444 function ErrorElement() {
445 const error = useAsyncError();
446 return (
447 <p>Uh Oh, something went wrong! {error.message}</p>
448 );
449 }
450
451 // somewhere in your app
452 <Await
453 resolve={promiseThatRejects}
454 errorElement={<ErrorElement />}
455 />
456 ```
457
458 @category Hooks
459 */
460declare function useAsyncError(): unknown;
461/**
462 * Allow the application to block navigations within the SPA and present the
463 * user a confirmation dialog to confirm the navigation. Mostly used to avoid
464 * using half-filled form data. This does not handle hard-reloads or
465 * cross-origin navigations.
466 *
467 * @category Hooks
468 */
469declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
470
471interface StaticRouterProps {
472 basename?: string;
473 children?: React.ReactNode;
474 location: Partial<Location> | string;
475}
476/**
477 * A `<Router>` that may not navigate to any other location. This is useful
478 * on the server where there is no stateful UI.
479 *
480 * @category Router Components
481 */
482declare function StaticRouter({ basename, children, location: locationProp, }: StaticRouterProps): React.JSX.Element;
483interface StaticRouterProviderProps {
484 context: StaticHandlerContext;
485 router: Router;
486 hydrate?: boolean;
487 nonce?: string;
488}
489/**
490 * A Data Router that may not navigate to any other location. This is useful
491 * on the server where there is no stateful UI.
492 *
493 * @category Router Components
494 */
495declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): React.JSX.Element;
496type CreateStaticHandlerOptions = Omit<CreateStaticHandlerOptions$1, "mapRouteProperties">;
497/**
498 * @category Utils
499 */
500declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
501/**
502 * @category Routers
503 */
504declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
505 future?: Partial<FutureConfig$1>;
506}): Router;
507
508interface ServerRouterProps {
509 context: EntryContext;
510 url: string | URL;
511 nonce?: string;
512}
513/**
514 * The entry point for a Remix app when it is rendered on the server (in
515 * `app/entry.server.js`). This component is used to generate the HTML in the
516 * response from the server.
517 *
518 * @category Components
519 */
520declare function ServerRouter({ context, url, nonce, }: ServerRouterProps): ReactElement;
521
522interface StubIndexRouteObject extends Omit<IndexRouteObject, "loader" | "action" | "element" | "errorElement" | "children"> {
523 loader?: LoaderFunction;
524 action?: ActionFunction;
525 children?: StubRouteObject[];
526 meta?: MetaFunction;
527 links?: LinksFunction;
528}
529interface StubNonIndexRouteObject extends Omit<NonIndexRouteObject, "loader" | "action" | "element" | "errorElement" | "children"> {
530 loader?: LoaderFunction;
531 action?: ActionFunction;
532 children?: StubRouteObject[];
533 meta?: MetaFunction;
534 links?: LinksFunction;
535}
536type StubRouteObject = StubIndexRouteObject | StubNonIndexRouteObject;
537interface AppLoadContext {
538 [key: string]: unknown;
539}
540interface RoutesTestStubProps {
541 /**
542 * The initial entries in the history stack. This allows you to start a test with
543 * multiple locations already in the history stack (for testing a back navigation, etc.)
544 * The test will default to the last entry in initialEntries if no initialIndex is provided.
545 * e.g. initialEntries={["/home", "/about", "/contact"]}
546 */
547 initialEntries?: InitialEntry[];
548 /**
549 * The initial index in the history stack to render. This allows you to start a test at a specific entry.
550 * It defaults to the last entry in initialEntries.
551 * e.g.
552 * initialEntries: ["/", "/events/123"]
553 * initialIndex: 1 // start at "/events/123"
554 */
555 initialIndex?: number;
556 /**
557 * Used to set the route's initial loader and action data.
558 * e.g. hydrationData={{
559 * loaderData: { "/contact": { locale: "en-US" } },
560 * actionData: { "/login": { errors: { email: "invalid email" } }}
561 * }}
562 */
563 hydrationData?: HydrationState;
564 /**
565 * Future flags mimicking the settings in react-router.config.ts
566 */
567 future?: Partial<FutureConfig>;
568}
569/**
570 * @category Utils
571 */
572declare function createRoutesStub(routes: StubRouteObject[], context?: AppLoadContext): ({ initialEntries, initialIndex, hydrationData, future, }: RoutesTestStubProps) => React.JSX.Element;
573
574interface CookieSignatureOptions {
575 /**
576 * An array of secrets that may be used to sign/unsign the value of a cookie.
577 *
578 * The array makes it easy to rotate secrets. New secrets should be added to
579 * the beginning of the array. `cookie.serialize()` will always use the first
580 * value in the array, but `cookie.parse()` may use any of them so that
581 * cookies that were signed with older secrets still work.
582 */
583 secrets?: string[];
584}
585type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
586/**
587 * A HTTP cookie.
588 *
589 * A Cookie is a logical container for metadata about a HTTP cookie; its name
590 * and options. But it doesn't contain a value. Instead, it has `parse()` and
591 * `serialize()` methods that allow a single instance to be reused for
592 * parsing/encoding multiple different values.
593 *
594 * @see https://remix.run/utils/cookies#cookie-api
595 */
596interface Cookie {
597 /**
598 * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
599 */
600 readonly name: string;
601 /**
602 * True if this cookie uses one or more secrets for verification.
603 */
604 readonly isSigned: boolean;
605 /**
606 * The Date this cookie expires.
607 *
608 * Note: This is calculated at access time using `maxAge` when no `expires`
609 * option is provided to `createCookie()`.
610 */
611 readonly expires?: Date;
612 /**
613 * Parses a raw `Cookie` header and returns the value of this cookie or
614 * `null` if it's not present.
615 */
616 parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
617 /**
618 * Serializes the given value to a string and returns the `Set-Cookie`
619 * header.
620 */
621 serialize(value: any, options?: SerializeOptions): Promise<string>;
622}
623/**
624 * Creates a logical container for managing a browser cookie from the server.
625 */
626declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
627type IsCookieFunction = (object: any) => object is Cookie;
628/**
629 * Returns true if an object is a Remix cookie container.
630 *
631 * @see https://remix.run/utils/cookies#iscookie
632 */
633declare const isCookie: IsCookieFunction;
634
635type RequestHandler = (request: Request, loadContext?: AppLoadContext$1) => Promise<Response>;
636type CreateRequestHandlerFunction = (build: ServerBuild | (() => ServerBuild | Promise<ServerBuild>), mode?: string) => RequestHandler;
637declare const createRequestHandler: CreateRequestHandlerFunction;
638
639/**
640 * An object of name/value pairs to be used in the session.
641 */
642interface SessionData {
643 [name: string]: any;
644}
645/**
646 * Session persists data across HTTP requests.
647 *
648 * @see https://remix.run/utils/sessions#session-api
649 */
650interface Session<Data = SessionData, FlashData = Data> {
651 /**
652 * A unique identifier for this session.
653 *
654 * Note: This will be the empty string for newly created sessions and
655 * sessions that are not backed by a database (i.e. cookie-based sessions).
656 */
657 readonly id: string;
658 /**
659 * The raw data contained in this session.
660 *
661 * This is useful mostly for SessionStorage internally to access the raw
662 * session data to persist.
663 */
664 readonly data: FlashSessionData<Data, FlashData>;
665 /**
666 * Returns `true` if the session has a value for the given `name`, `false`
667 * otherwise.
668 */
669 has(name: (keyof Data | keyof FlashData) & string): boolean;
670 /**
671 * Returns the value for the given `name` in this session.
672 */
673 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;
674 /**
675 * Sets a value in the session for the given `name`.
676 */
677 set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
678 /**
679 * Sets a value in the session that is only valid until the next `get()`.
680 * This can be useful for temporary values, like error messages.
681 */
682 flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
683 /**
684 * Removes a value from the session.
685 */
686 unset(name: keyof Data & string): void;
687}
688type FlashSessionData<Data, FlashData> = Partial<Data & {
689 [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
690}>;
691type FlashDataKey<Key extends string> = `__flash_${Key}__`;
692type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
693/**
694 * Creates a new Session object.
695 *
696 * Note: This function is typically not invoked directly by application code.
697 * Instead, use a `SessionStorage` object's `getSession` method.
698 *
699 * @see https://remix.run/utils/sessions#createsession
700 */
701declare const createSession: CreateSessionFunction;
702type IsSessionFunction = (object: any) => object is Session;
703/**
704 * Returns true if an object is a Remix session.
705 *
706 * @see https://remix.run/utils/sessions#issession
707 */
708declare const isSession: IsSessionFunction;
709/**
710 * SessionStorage stores session data between HTTP requests and knows how to
711 * parse and create cookies.
712 *
713 * A SessionStorage creates Session objects using a `Cookie` header as input.
714 * Then, later it generates the `Set-Cookie` header to be used in the response.
715 */
716interface SessionStorage<Data = SessionData, FlashData = Data> {
717 /**
718 * Parses a Cookie header from a HTTP request and returns the associated
719 * Session. If there is no session associated with the cookie, this will
720 * return a new Session with no data.
721 */
722 getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
723 /**
724 * Stores all data in the Session and returns the Set-Cookie header to be
725 * used in the HTTP response.
726 */
727 commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
728 /**
729 * Deletes all data associated with the Session and returns the Set-Cookie
730 * header to be used in the HTTP response.
731 */
732 destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
733}
734/**
735 * SessionIdStorageStrategy is designed to allow anyone to easily build their
736 * own SessionStorage using `createSessionStorage(strategy)`.
737 *
738 * This strategy describes a common scenario where the session id is stored in
739 * a cookie but the actual session data is stored elsewhere, usually in a
740 * database or on disk. A set of create, read, update, and delete operations
741 * are provided for managing the session data.
742 */
743interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
744 /**
745 * The Cookie used to store the session id, or options used to automatically
746 * create one.
747 */
748 cookie?: Cookie | (CookieOptions & {
749 name?: string;
750 });
751 /**
752 * Creates a new record with the given data and returns the session id.
753 */
754 createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
755 /**
756 * Returns data for a given session id, or `null` if there isn't any.
757 */
758 readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
759 /**
760 * Updates data for the given session id.
761 */
762 updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
763 /**
764 * Deletes data for a given session id from the data store.
765 */
766 deleteData: (id: string) => Promise<void>;
767}
768/**
769 * Creates a SessionStorage object using a SessionIdStorageStrategy.
770 *
771 * Note: This is a low-level API that should only be used if none of the
772 * existing session storage options meet your requirements.
773 */
774declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
775
776interface CookieSessionStorageOptions {
777 /**
778 * The Cookie used to store the session data on the client, or options used
779 * to automatically create one.
780 */
781 cookie?: SessionIdStorageStrategy["cookie"];
782}
783/**
784 * Creates and returns a SessionStorage object that stores all session data
785 * directly in the session cookie itself.
786 *
787 * This has the advantage that no database or other backend services are
788 * needed, and can help to simplify some load-balanced scenarios. However, it
789 * also has the limitation that serialized session data may not exceed the
790 * browser's maximum cookie size. Trade-offs!
791 */
792declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
793
794interface MemorySessionStorageOptions {
795 /**
796 * The Cookie used to store the session id on the client, or options used
797 * to automatically create one.
798 */
799 cookie?: SessionIdStorageStrategy["cookie"];
800}
801/**
802 * Creates and returns a simple in-memory SessionStorage object, mostly useful
803 * for testing and as a reference implementation.
804 *
805 * Note: This storage does not scale beyond a single process, so it is not
806 * suitable for most production scenarios.
807 */
808declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
809
810type DevServerHooks = {
811 getCriticalCss?: (build: ServerBuild, pathname: string) => Promise<string | undefined>;
812 processRequestError?: (error: unknown) => void;
813};
814declare function setDevServerHooks(devServerHooks: DevServerHooks): void;
815
816declare function deserializeErrors(errors: RouterState["errors"]): RouterState["errors"];
817
818type RemixErrorBoundaryProps = React.PropsWithChildren<{
819 location: Location;
820 isOutsideRemixApp?: boolean;
821 error?: Error;
822}>;
823type RemixErrorBoundaryState = {
824 error: null | Error;
825 location: Location;
826};
827declare class RemixErrorBoundary extends React.Component<RemixErrorBoundaryProps, RemixErrorBoundaryState> {
828 constructor(props: RemixErrorBoundaryProps);
829 static getDerivedStateFromError(error: Error): {
830 error: Error;
831 };
832 static getDerivedStateFromProps(props: RemixErrorBoundaryProps, state: RemixErrorBoundaryState): {
833 error: Error | null;
834 location: Location<any>;
835 };
836 render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
837}
838
839export { ActionFunction, ActionFunctionArgs, AppLoadContext$1 as AppLoadContext, Blocker, BlockerFunction, ClientActionFunction, ClientLoaderFunction, type Cookie, type CookieOptions, type CookieSignatureOptions, type CreateRequestHandlerFunction, Router as DataRouter, DataStrategyFunction, EntryContext, type FlashSessionData, type HandleDataRequestFunction, type HandleDocumentRequestFunction, type HandleErrorFunction, type HeadersArgs, type HeadersFunction, HydrationState, IndexRouteObject, InitialEntry, type IsCookieFunction, type IsSessionFunction, LinksFunction, LoaderFunction, LoaderFunctionArgs, Location, MetaFunction, type NavigateFunction, NavigateOptions, Navigation, Action as NavigationType, NonIndexRouteObject, ParamParseKey, Params, Path, PathMatch, PathPattern, RelativeRoutingType, type RequestHandler, RevalidationState, RouteObject, RouterState, type RoutesTestStubProps, type ServerBuild, type ServerEntryModule, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, StaticHandler, StaticHandlerContext, StaticRouter, type StaticRouterProps, StaticRouterProvider, type StaticRouterProviderProps, To, UIMatch, AssetsManifest as UNSAFE_AssetsManifest, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteModules as UNSAFE_RouteModules, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getSingleFetchDataStrategy as UNSAFE_getSingleFetchDataStrategy, createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createRoutesStub, createSession, createSessionStorage, createStaticHandler, createStaticRouter, isCookie, isSession, setDevServerHooks as unstable_setDevServerHooks, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };