1 | import type { Location, Path, To } from "./history";
|
---|
2 | /**
|
---|
3 | * Map of routeId -> data returned from a loader/action/error
|
---|
4 | */
|
---|
5 | export interface RouteData {
|
---|
6 | [routeId: string]: any;
|
---|
7 | }
|
---|
8 | export declare enum ResultType {
|
---|
9 | data = "data",
|
---|
10 | deferred = "deferred",
|
---|
11 | redirect = "redirect",
|
---|
12 | error = "error"
|
---|
13 | }
|
---|
14 | /**
|
---|
15 | * Successful result from a loader or action
|
---|
16 | */
|
---|
17 | export interface SuccessResult {
|
---|
18 | type: ResultType.data;
|
---|
19 | data: unknown;
|
---|
20 | statusCode?: number;
|
---|
21 | headers?: Headers;
|
---|
22 | }
|
---|
23 | /**
|
---|
24 | * Successful defer() result from a loader or action
|
---|
25 | */
|
---|
26 | export interface DeferredResult {
|
---|
27 | type: ResultType.deferred;
|
---|
28 | deferredData: DeferredData;
|
---|
29 | statusCode?: number;
|
---|
30 | headers?: Headers;
|
---|
31 | }
|
---|
32 | /**
|
---|
33 | * Redirect result from a loader or action
|
---|
34 | */
|
---|
35 | export interface RedirectResult {
|
---|
36 | type: ResultType.redirect;
|
---|
37 | response: Response;
|
---|
38 | }
|
---|
39 | /**
|
---|
40 | * Unsuccessful result from a loader or action
|
---|
41 | */
|
---|
42 | export interface ErrorResult {
|
---|
43 | type: ResultType.error;
|
---|
44 | error: unknown;
|
---|
45 | statusCode?: number;
|
---|
46 | headers?: Headers;
|
---|
47 | }
|
---|
48 | /**
|
---|
49 | * Result from a loader or action - potentially successful or unsuccessful
|
---|
50 | */
|
---|
51 | export type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
|
---|
52 | /**
|
---|
53 | * Result from a loader or action called via dataStrategy
|
---|
54 | */
|
---|
55 | export interface HandlerResult {
|
---|
56 | type: "data" | "error";
|
---|
57 | result: unknown;
|
---|
58 | }
|
---|
59 | type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
|
---|
60 | type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
|
---|
61 | /**
|
---|
62 | * Users can specify either lowercase or uppercase form methods on `<Form>`,
|
---|
63 | * useSubmit(), `<fetcher.Form>`, etc.
|
---|
64 | */
|
---|
65 | export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
|
---|
66 | /**
|
---|
67 | * Active navigation/fetcher form methods are exposed in lowercase on the
|
---|
68 | * RouterState
|
---|
69 | */
|
---|
70 | export type FormMethod = LowerCaseFormMethod;
|
---|
71 | export type MutationFormMethod = Exclude<FormMethod, "get">;
|
---|
72 | /**
|
---|
73 | * In v7, active navigation/fetcher form methods are exposed in uppercase on the
|
---|
74 | * RouterState. This is to align with the normalization done via fetch().
|
---|
75 | */
|
---|
76 | export type V7_FormMethod = UpperCaseFormMethod;
|
---|
77 | export type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
|
---|
78 | export type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
|
---|
79 | type JsonObject = {
|
---|
80 | [Key in string]: JsonValue;
|
---|
81 | } & {
|
---|
82 | [Key in string]?: JsonValue | undefined;
|
---|
83 | };
|
---|
84 | type JsonArray = JsonValue[] | readonly JsonValue[];
|
---|
85 | type JsonPrimitive = string | number | boolean | null;
|
---|
86 | type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
---|
87 | /**
|
---|
88 | * @private
|
---|
89 | * Internal interface to pass around for action submissions, not intended for
|
---|
90 | * external consumption
|
---|
91 | */
|
---|
92 | export type Submission = {
|
---|
93 | formMethod: FormMethod | V7_FormMethod;
|
---|
94 | formAction: string;
|
---|
95 | formEncType: FormEncType;
|
---|
96 | formData: FormData;
|
---|
97 | json: undefined;
|
---|
98 | text: undefined;
|
---|
99 | } | {
|
---|
100 | formMethod: FormMethod | V7_FormMethod;
|
---|
101 | formAction: string;
|
---|
102 | formEncType: FormEncType;
|
---|
103 | formData: undefined;
|
---|
104 | json: JsonValue;
|
---|
105 | text: undefined;
|
---|
106 | } | {
|
---|
107 | formMethod: FormMethod | V7_FormMethod;
|
---|
108 | formAction: string;
|
---|
109 | formEncType: FormEncType;
|
---|
110 | formData: undefined;
|
---|
111 | json: undefined;
|
---|
112 | text: string;
|
---|
113 | };
|
---|
114 | /**
|
---|
115 | * @private
|
---|
116 | * Arguments passed to route loader/action functions. Same for now but we keep
|
---|
117 | * this as a private implementation detail in case they diverge in the future.
|
---|
118 | */
|
---|
119 | interface DataFunctionArgs<Context> {
|
---|
120 | request: Request;
|
---|
121 | params: Params;
|
---|
122 | context?: Context;
|
---|
123 | }
|
---|
124 | /**
|
---|
125 | * Arguments passed to loader functions
|
---|
126 | */
|
---|
127 | export interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
|
---|
128 | }
|
---|
129 | /**
|
---|
130 | * Arguments passed to action functions
|
---|
131 | */
|
---|
132 | export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
|
---|
133 | }
|
---|
134 | /**
|
---|
135 | * Loaders and actions can return anything except `undefined` (`null` is a
|
---|
136 | * valid return value if there is no data to return). Responses are preferred
|
---|
137 | * and will ease any future migration to Remix
|
---|
138 | */
|
---|
139 | type DataFunctionValue = Response | NonNullable<unknown> | null;
|
---|
140 | type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
|
---|
141 | /**
|
---|
142 | * Route loader function signature
|
---|
143 | */
|
---|
144 | export type LoaderFunction<Context = any> = {
|
---|
145 | (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
|
---|
146 | } & {
|
---|
147 | hydrate?: boolean;
|
---|
148 | };
|
---|
149 | /**
|
---|
150 | * Route action function signature
|
---|
151 | */
|
---|
152 | export interface ActionFunction<Context = any> {
|
---|
153 | (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
|
---|
154 | }
|
---|
155 | /**
|
---|
156 | * Arguments passed to shouldRevalidate function
|
---|
157 | */
|
---|
158 | export interface ShouldRevalidateFunctionArgs {
|
---|
159 | currentUrl: URL;
|
---|
160 | currentParams: AgnosticDataRouteMatch["params"];
|
---|
161 | nextUrl: URL;
|
---|
162 | nextParams: AgnosticDataRouteMatch["params"];
|
---|
163 | formMethod?: Submission["formMethod"];
|
---|
164 | formAction?: Submission["formAction"];
|
---|
165 | formEncType?: Submission["formEncType"];
|
---|
166 | text?: Submission["text"];
|
---|
167 | formData?: Submission["formData"];
|
---|
168 | json?: Submission["json"];
|
---|
169 | actionStatus?: number;
|
---|
170 | actionResult?: any;
|
---|
171 | defaultShouldRevalidate: boolean;
|
---|
172 | }
|
---|
173 | /**
|
---|
174 | * Route shouldRevalidate function signature. This runs after any submission
|
---|
175 | * (navigation or fetcher), so we flatten the navigation/fetcher submission
|
---|
176 | * onto the arguments. It shouldn't matter whether it came from a navigation
|
---|
177 | * or a fetcher, what really matters is the URLs and the formData since loaders
|
---|
178 | * have to re-run based on the data models that were potentially mutated.
|
---|
179 | */
|
---|
180 | export interface ShouldRevalidateFunction {
|
---|
181 | (args: ShouldRevalidateFunctionArgs): boolean;
|
---|
182 | }
|
---|
183 | /**
|
---|
184 | * Function provided by the framework-aware layers to set `hasErrorBoundary`
|
---|
185 | * from the framework-aware `errorElement` prop
|
---|
186 | *
|
---|
187 | * @deprecated Use `mapRouteProperties` instead
|
---|
188 | */
|
---|
189 | export interface DetectErrorBoundaryFunction {
|
---|
190 | (route: AgnosticRouteObject): boolean;
|
---|
191 | }
|
---|
192 | export interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
|
---|
193 | shouldLoad: boolean;
|
---|
194 | resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => Promise<HandlerResult>) => Promise<HandlerResult>;
|
---|
195 | }
|
---|
196 | export interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
|
---|
197 | matches: DataStrategyMatch[];
|
---|
198 | }
|
---|
199 | export interface DataStrategyFunction {
|
---|
200 | (args: DataStrategyFunctionArgs): Promise<HandlerResult[]>;
|
---|
201 | }
|
---|
202 | export interface AgnosticPatchRoutesOnMissFunction<M extends AgnosticRouteMatch = AgnosticRouteMatch> {
|
---|
203 | (opts: {
|
---|
204 | path: string;
|
---|
205 | matches: M[];
|
---|
206 | patch: (routeId: string | null, children: AgnosticRouteObject[]) => void;
|
---|
207 | }): void | Promise<void>;
|
---|
208 | }
|
---|
209 | /**
|
---|
210 | * Function provided by the framework-aware layers to set any framework-specific
|
---|
211 | * properties from framework-agnostic properties
|
---|
212 | */
|
---|
213 | export interface MapRoutePropertiesFunction {
|
---|
214 | (route: AgnosticRouteObject): {
|
---|
215 | hasErrorBoundary: boolean;
|
---|
216 | } & Record<string, any>;
|
---|
217 | }
|
---|
218 | /**
|
---|
219 | * Keys we cannot change from within a lazy() function. We spread all other keys
|
---|
220 | * onto the route. Either they're meaningful to the router, or they'll get
|
---|
221 | * ignored.
|
---|
222 | */
|
---|
223 | export type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
|
---|
224 | export declare const immutableRouteKeys: Set<ImmutableRouteKey>;
|
---|
225 | type RequireOne<T, Key = keyof T> = Exclude<{
|
---|
226 | [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
|
---|
227 | }[keyof T], undefined>;
|
---|
228 | /**
|
---|
229 | * lazy() function to load a route definition, which can add non-matching
|
---|
230 | * related properties to a route
|
---|
231 | */
|
---|
232 | export interface LazyRouteFunction<R extends AgnosticRouteObject> {
|
---|
233 | (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
|
---|
234 | }
|
---|
235 | /**
|
---|
236 | * Base RouteObject with common props shared by all types of routes
|
---|
237 | */
|
---|
238 | type AgnosticBaseRouteObject = {
|
---|
239 | caseSensitive?: boolean;
|
---|
240 | path?: string;
|
---|
241 | id?: string;
|
---|
242 | loader?: LoaderFunction | boolean;
|
---|
243 | action?: ActionFunction | boolean;
|
---|
244 | hasErrorBoundary?: boolean;
|
---|
245 | shouldRevalidate?: ShouldRevalidateFunction;
|
---|
246 | handle?: any;
|
---|
247 | lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
|
---|
248 | };
|
---|
249 | /**
|
---|
250 | * Index routes must not have children
|
---|
251 | */
|
---|
252 | export type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
|
---|
253 | children?: undefined;
|
---|
254 | index: true;
|
---|
255 | };
|
---|
256 | /**
|
---|
257 | * Non-index routes may have children, but cannot have index
|
---|
258 | */
|
---|
259 | export type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
|
---|
260 | children?: AgnosticRouteObject[];
|
---|
261 | index?: false;
|
---|
262 | };
|
---|
263 | /**
|
---|
264 | * A route object represents a logical route, with (optionally) its child
|
---|
265 | * routes organized in a tree-like structure.
|
---|
266 | */
|
---|
267 | export type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
|
---|
268 | export type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
|
---|
269 | id: string;
|
---|
270 | };
|
---|
271 | export type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
|
---|
272 | children?: AgnosticDataRouteObject[];
|
---|
273 | id: string;
|
---|
274 | };
|
---|
275 | /**
|
---|
276 | * A data route object, which is just a RouteObject with a required unique ID
|
---|
277 | */
|
---|
278 | export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
|
---|
279 | export type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
|
---|
280 | type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?` ? Optional : Param : never;
|
---|
281 | /**
|
---|
282 | * Examples:
|
---|
283 | * "/a/b/*" -> "*"
|
---|
284 | * ":a" -> "a"
|
---|
285 | * "/a/:b" -> "b"
|
---|
286 | * "/a/blahblahblah:b" -> "b"
|
---|
287 | * "/:a/:b" -> "a" | "b"
|
---|
288 | * "/:a/b/:c/*" -> "a" | "c" | "*"
|
---|
289 | */
|
---|
290 | export type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
|
---|
291 | export type ParamParseKey<Segment extends string> = [
|
---|
292 | PathParam<Segment>
|
---|
293 | ] extends [never] ? string : PathParam<Segment>;
|
---|
294 | /**
|
---|
295 | * The parameters that were parsed from the URL path.
|
---|
296 | */
|
---|
297 | export type Params<Key extends string = string> = {
|
---|
298 | readonly [key in Key]: string | undefined;
|
---|
299 | };
|
---|
300 | /**
|
---|
301 | * A RouteMatch contains info about how a route matched a URL.
|
---|
302 | */
|
---|
303 | export interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
|
---|
304 | /**
|
---|
305 | * The names and values of dynamic parameters in the URL.
|
---|
306 | */
|
---|
307 | params: Params<ParamKey>;
|
---|
308 | /**
|
---|
309 | * The portion of the URL pathname that was matched.
|
---|
310 | */
|
---|
311 | pathname: string;
|
---|
312 | /**
|
---|
313 | * The portion of the URL pathname that was matched before child routes.
|
---|
314 | */
|
---|
315 | pathnameBase: string;
|
---|
316 | /**
|
---|
317 | * The route object that was used to match.
|
---|
318 | */
|
---|
319 | route: RouteObjectType;
|
---|
320 | }
|
---|
321 | export interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
|
---|
322 | }
|
---|
323 | export declare function convertRoutesToDataRoutes(routes: AgnosticRouteObject[], mapRouteProperties: MapRoutePropertiesFunction, parentPath?: string[], manifest?: RouteManifest): AgnosticDataRouteObject[];
|
---|
324 | /**
|
---|
325 | * Matches the given routes to a location and returns the match data.
|
---|
326 | *
|
---|
327 | * @see https://reactrouter.com/utils/match-routes
|
---|
328 | */
|
---|
329 | export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
---|
330 | export declare function matchRoutesImpl<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename: string, allowPartial: boolean): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
---|
331 | export interface UIMatch<Data = unknown, Handle = unknown> {
|
---|
332 | id: string;
|
---|
333 | pathname: string;
|
---|
334 | params: AgnosticRouteMatch["params"];
|
---|
335 | data: Data;
|
---|
336 | handle: Handle;
|
---|
337 | }
|
---|
338 | export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
|
---|
339 | /**
|
---|
340 | * Returns a path with params interpolated.
|
---|
341 | *
|
---|
342 | * @see https://reactrouter.com/utils/generate-path
|
---|
343 | */
|
---|
344 | export declare function generatePath<Path extends string>(originalPath: Path, params?: {
|
---|
345 | [key in PathParam<Path>]: string | null;
|
---|
346 | }): string;
|
---|
347 | /**
|
---|
348 | * A PathPattern is used to match on some portion of a URL pathname.
|
---|
349 | */
|
---|
350 | export interface PathPattern<Path extends string = string> {
|
---|
351 | /**
|
---|
352 | * A string to match against a URL pathname. May contain `:id`-style segments
|
---|
353 | * to indicate placeholders for dynamic parameters. May also end with `/*` to
|
---|
354 | * indicate matching the rest of the URL pathname.
|
---|
355 | */
|
---|
356 | path: Path;
|
---|
357 | /**
|
---|
358 | * Should be `true` if the static portions of the `path` should be matched in
|
---|
359 | * the same case.
|
---|
360 | */
|
---|
361 | caseSensitive?: boolean;
|
---|
362 | /**
|
---|
363 | * Should be `true` if this pattern should match the entire URL pathname.
|
---|
364 | */
|
---|
365 | end?: boolean;
|
---|
366 | }
|
---|
367 | /**
|
---|
368 | * A PathMatch contains info about how a PathPattern matched on a URL pathname.
|
---|
369 | */
|
---|
370 | export interface PathMatch<ParamKey extends string = string> {
|
---|
371 | /**
|
---|
372 | * The names and values of dynamic parameters in the URL.
|
---|
373 | */
|
---|
374 | params: Params<ParamKey>;
|
---|
375 | /**
|
---|
376 | * The portion of the URL pathname that was matched.
|
---|
377 | */
|
---|
378 | pathname: string;
|
---|
379 | /**
|
---|
380 | * The portion of the URL pathname that was matched before child routes.
|
---|
381 | */
|
---|
382 | pathnameBase: string;
|
---|
383 | /**
|
---|
384 | * The pattern that was used to match.
|
---|
385 | */
|
---|
386 | pattern: PathPattern;
|
---|
387 | }
|
---|
388 | /**
|
---|
389 | * Performs pattern matching on a URL pathname and returns information about
|
---|
390 | * the match.
|
---|
391 | *
|
---|
392 | * @see https://reactrouter.com/utils/match-path
|
---|
393 | */
|
---|
394 | export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
|
---|
395 | export declare function decodePath(value: string): string;
|
---|
396 | /**
|
---|
397 | * @private
|
---|
398 | */
|
---|
399 | export declare function stripBasename(pathname: string, basename: string): string | null;
|
---|
400 | /**
|
---|
401 | * Returns a resolved path object relative to the given pathname.
|
---|
402 | *
|
---|
403 | * @see https://reactrouter.com/utils/resolve-path
|
---|
404 | */
|
---|
405 | export declare function resolvePath(to: To, fromPathname?: string): Path;
|
---|
406 | /**
|
---|
407 | * @private
|
---|
408 | *
|
---|
409 | * When processing relative navigation we want to ignore ancestor routes that
|
---|
410 | * do not contribute to the path, such that index/pathless layout routes don't
|
---|
411 | * interfere.
|
---|
412 | *
|
---|
413 | * For example, when moving a route element into an index route and/or a
|
---|
414 | * pathless layout route, relative link behavior contained within should stay
|
---|
415 | * the same. Both of the following examples should link back to the root:
|
---|
416 | *
|
---|
417 | * <Route path="/">
|
---|
418 | * <Route path="accounts" element={<Link to=".."}>
|
---|
419 | * </Route>
|
---|
420 | *
|
---|
421 | * <Route path="/">
|
---|
422 | * <Route path="accounts">
|
---|
423 | * <Route element={<AccountsLayout />}> // <-- Does not contribute
|
---|
424 | * <Route index element={<Link to=".."} /> // <-- Does not contribute
|
---|
425 | * </Route
|
---|
426 | * </Route>
|
---|
427 | * </Route>
|
---|
428 | */
|
---|
429 | export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
|
---|
430 | export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[], v7_relativeSplatPath: boolean): string[];
|
---|
431 | /**
|
---|
432 | * @private
|
---|
433 | */
|
---|
434 | export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string, isPathRelative?: boolean): Path;
|
---|
435 | /**
|
---|
436 | * @private
|
---|
437 | */
|
---|
438 | export declare function getToPathname(to: To): string | undefined;
|
---|
439 | /**
|
---|
440 | * @private
|
---|
441 | */
|
---|
442 | export declare const joinPaths: (paths: string[]) => string;
|
---|
443 | /**
|
---|
444 | * @private
|
---|
445 | */
|
---|
446 | export declare const normalizePathname: (pathname: string) => string;
|
---|
447 | /**
|
---|
448 | * @private
|
---|
449 | */
|
---|
450 | export declare const normalizeSearch: (search: string) => string;
|
---|
451 | /**
|
---|
452 | * @private
|
---|
453 | */
|
---|
454 | export declare const normalizeHash: (hash: string) => string;
|
---|
455 | export type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => Response;
|
---|
456 | /**
|
---|
457 | * This is a shortcut for creating `application/json` responses. Converts `data`
|
---|
458 | * to JSON and sets the `Content-Type` header.
|
---|
459 | */
|
---|
460 | export declare const json: JsonFunction;
|
---|
461 | export declare class DataWithResponseInit<D> {
|
---|
462 | type: string;
|
---|
463 | data: D;
|
---|
464 | init: ResponseInit | null;
|
---|
465 | constructor(data: D, init?: ResponseInit);
|
---|
466 | }
|
---|
467 | /**
|
---|
468 | * Create "responses" that contain `status`/`headers` without forcing
|
---|
469 | * serialization into an actual `Response` - used by Remix single fetch
|
---|
470 | */
|
---|
471 | export declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
|
---|
472 | export interface TrackedPromise extends Promise<any> {
|
---|
473 | _tracked?: boolean;
|
---|
474 | _data?: any;
|
---|
475 | _error?: any;
|
---|
476 | }
|
---|
477 | export declare class AbortedDeferredError extends Error {
|
---|
478 | }
|
---|
479 | export declare class DeferredData {
|
---|
480 | private pendingKeysSet;
|
---|
481 | private controller;
|
---|
482 | private abortPromise;
|
---|
483 | private unlistenAbortSignal;
|
---|
484 | private subscribers;
|
---|
485 | data: Record<string, unknown>;
|
---|
486 | init?: ResponseInit;
|
---|
487 | deferredKeys: string[];
|
---|
488 | constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
|
---|
489 | private trackPromise;
|
---|
490 | private onSettle;
|
---|
491 | private emit;
|
---|
492 | subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
|
---|
493 | cancel(): void;
|
---|
494 | resolveData(signal: AbortSignal): Promise<boolean>;
|
---|
495 | get done(): boolean;
|
---|
496 | get unwrappedData(): {};
|
---|
497 | get pendingKeys(): string[];
|
---|
498 | }
|
---|
499 | export type DeferFunction = (data: Record<string, unknown>, init?: number | ResponseInit) => DeferredData;
|
---|
500 | export declare const defer: DeferFunction;
|
---|
501 | export type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
---|
502 | /**
|
---|
503 | * A redirect response. Sets the status code and the `Location` header.
|
---|
504 | * Defaults to "302 Found".
|
---|
505 | */
|
---|
506 | export declare const redirect: RedirectFunction;
|
---|
507 | /**
|
---|
508 | * A redirect response that will force a document reload to the new location.
|
---|
509 | * Sets the status code and the `Location` header.
|
---|
510 | * Defaults to "302 Found".
|
---|
511 | */
|
---|
512 | export declare const redirectDocument: RedirectFunction;
|
---|
513 | /**
|
---|
514 | * A redirect response that will perform a `history.replaceState` instead of a
|
---|
515 | * `history.pushState` for client-side navigation redirects.
|
---|
516 | * Sets the status code and the `Location` header.
|
---|
517 | * Defaults to "302 Found".
|
---|
518 | */
|
---|
519 | export declare const replace: RedirectFunction;
|
---|
520 | export type ErrorResponse = {
|
---|
521 | status: number;
|
---|
522 | statusText: string;
|
---|
523 | data: any;
|
---|
524 | };
|
---|
525 | /**
|
---|
526 | * @private
|
---|
527 | * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
|
---|
528 | *
|
---|
529 | * We don't export the class for public use since it's an implementation
|
---|
530 | * detail, but we export the interface above so folks can build their own
|
---|
531 | * abstractions around instances via isRouteErrorResponse()
|
---|
532 | */
|
---|
533 | export declare class ErrorResponseImpl implements ErrorResponse {
|
---|
534 | status: number;
|
---|
535 | statusText: string;
|
---|
536 | data: any;
|
---|
537 | private error?;
|
---|
538 | private internal;
|
---|
539 | constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
|
---|
540 | }
|
---|
541 | /**
|
---|
542 | * Check if the given error is an ErrorResponse generated from a 4xx/5xx
|
---|
543 | * Response thrown from an action/loader
|
---|
544 | */
|
---|
545 | export declare function isRouteErrorResponse(error: any): error is ErrorResponse;
|
---|
546 | export {};
|
---|