source: imaps-frontend/node_modules/@remix-run/router/dist/utils.d.ts@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 19.0 KB
RevLine 
[d565449]1import type { Location, Path, To } from "./history";
2/**
3 * Map of routeId -> data returned from a loader/action/error
4 */
5export interface RouteData {
6 [routeId: string]: any;
7}
8export 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 */
17export 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 */
26export 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 */
35export interface RedirectResult {
36 type: ResultType.redirect;
37 response: Response;
38}
39/**
40 * Unsuccessful result from a loader or action
41 */
42export 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 */
51export type DataResult = SuccessResult | DeferredResult | RedirectResult | ErrorResult;
52type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
53type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
54/**
55 * Users can specify either lowercase or uppercase form methods on `<Form>`,
56 * useSubmit(), `<fetcher.Form>`, etc.
57 */
58export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
59/**
60 * Active navigation/fetcher form methods are exposed in lowercase on the
61 * RouterState
62 */
63export type FormMethod = LowerCaseFormMethod;
64export type MutationFormMethod = Exclude<FormMethod, "get">;
65/**
66 * In v7, active navigation/fetcher form methods are exposed in uppercase on the
67 * RouterState. This is to align with the normalization done via fetch().
68 */
69export type V7_FormMethod = UpperCaseFormMethod;
70export type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
71export type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
72type JsonObject = {
73 [Key in string]: JsonValue;
74} & {
75 [Key in string]?: JsonValue | undefined;
76};
77type JsonArray = JsonValue[] | readonly JsonValue[];
78type JsonPrimitive = string | number | boolean | null;
79type JsonValue = JsonPrimitive | JsonObject | JsonArray;
80/**
81 * @private
82 * Internal interface to pass around for action submissions, not intended for
83 * external consumption
84 */
85export type Submission = {
86 formMethod: FormMethod | V7_FormMethod;
87 formAction: string;
88 formEncType: FormEncType;
89 formData: FormData;
90 json: undefined;
91 text: undefined;
92} | {
93 formMethod: FormMethod | V7_FormMethod;
94 formAction: string;
95 formEncType: FormEncType;
96 formData: undefined;
97 json: JsonValue;
98 text: undefined;
99} | {
100 formMethod: FormMethod | V7_FormMethod;
101 formAction: string;
102 formEncType: FormEncType;
103 formData: undefined;
104 json: undefined;
105 text: string;
106};
107/**
108 * @private
109 * Arguments passed to route loader/action functions. Same for now but we keep
110 * this as a private implementation detail in case they diverge in the future.
111 */
112interface DataFunctionArgs<Context> {
113 request: Request;
114 params: Params;
115 context?: Context;
116}
117/**
118 * Arguments passed to loader functions
119 */
120export interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
121}
122/**
123 * Arguments passed to action functions
124 */
125export interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
126}
127/**
128 * Loaders and actions can return anything except `undefined` (`null` is a
129 * valid return value if there is no data to return). Responses are preferred
130 * and will ease any future migration to Remix
131 */
132type DataFunctionValue = Response | NonNullable<unknown> | null;
133type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
134/**
135 * Route loader function signature
136 */
137export type LoaderFunction<Context = any> = {
138 (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
139} & {
140 hydrate?: boolean;
141};
142/**
143 * Route action function signature
144 */
145export interface ActionFunction<Context = any> {
146 (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
147}
148/**
149 * Arguments passed to shouldRevalidate function
150 */
151export interface ShouldRevalidateFunctionArgs {
152 currentUrl: URL;
153 currentParams: AgnosticDataRouteMatch["params"];
154 nextUrl: URL;
155 nextParams: AgnosticDataRouteMatch["params"];
156 formMethod?: Submission["formMethod"];
157 formAction?: Submission["formAction"];
158 formEncType?: Submission["formEncType"];
159 text?: Submission["text"];
160 formData?: Submission["formData"];
161 json?: Submission["json"];
162 actionStatus?: number;
163 actionResult?: any;
164 defaultShouldRevalidate: boolean;
165}
166/**
167 * Route shouldRevalidate function signature. This runs after any submission
168 * (navigation or fetcher), so we flatten the navigation/fetcher submission
169 * onto the arguments. It shouldn't matter whether it came from a navigation
170 * or a fetcher, what really matters is the URLs and the formData since loaders
171 * have to re-run based on the data models that were potentially mutated.
172 */
173export interface ShouldRevalidateFunction {
174 (args: ShouldRevalidateFunctionArgs): boolean;
175}
176/**
177 * Function provided by the framework-aware layers to set `hasErrorBoundary`
178 * from the framework-aware `errorElement` prop
179 *
180 * @deprecated Use `mapRouteProperties` instead
181 */
182export interface DetectErrorBoundaryFunction {
183 (route: AgnosticRouteObject): boolean;
184}
185export interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
186 shouldLoad: boolean;
[0c6b92a]187 resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
[d565449]188}
189export interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
190 matches: DataStrategyMatch[];
[0c6b92a]191 fetcherKey: string | null;
[d565449]192}
[0c6b92a]193/**
194 * Result from a loader or action called via dataStrategy
195 */
196export interface DataStrategyResult {
197 type: "data" | "error";
198 result: unknown;
[d565449]199}
[0c6b92a]200export interface DataStrategyFunction {
201 (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
[d565449]202}
[0c6b92a]203export type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
204 path: string;
205 matches: M[];
206 patch: (routeId: string | null, children: O[]) => void;
207};
208export type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => void | Promise<void>;
[d565449]209/**
210 * Function provided by the framework-aware layers to set any framework-specific
211 * properties from framework-agnostic properties
212 */
213export 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 */
223export type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
224export declare const immutableRouteKeys: Set<ImmutableRouteKey>;
225type 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 */
232export 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 */
238type 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 */
252export type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
253 children?: undefined;
254 index: true;
255};
256/**
257 * Non-index routes may have children, but cannot have index
258 */
259export 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 */
267export type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
268export type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
269 id: string;
270};
271export 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 */
278export type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
279export type RouteManifest = Record<string, AgnosticDataRouteObject | undefined>;
280type _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 */
290export type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
291export 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 */
297export 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 */
303export 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}
321export interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
322}
323export 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 *
[0c6b92a]327 * @see https://reactrouter.com/v6/utils/match-routes
[d565449]328 */
329export declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
330export declare function matchRoutesImpl<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename: string, allowPartial: boolean): AgnosticRouteMatch<string, RouteObjectType>[] | null;
331export interface UIMatch<Data = unknown, Handle = unknown> {
332 id: string;
333 pathname: string;
334 params: AgnosticRouteMatch["params"];
335 data: Data;
336 handle: Handle;
337}
338export declare function convertRouteMatchToUiMatch(match: AgnosticDataRouteMatch, loaderData: RouteData): UIMatch;
339/**
340 * Returns a path with params interpolated.
341 *
[0c6b92a]342 * @see https://reactrouter.com/v6/utils/generate-path
[d565449]343 */
344export 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 */
350export 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 */
370export 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 *
[0c6b92a]392 * @see https://reactrouter.com/v6/utils/match-path
[d565449]393 */
394export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
395export declare function decodePath(value: string): string;
396/**
397 * @private
398 */
399export declare function stripBasename(pathname: string, basename: string): string | null;
400/**
401 * Returns a resolved path object relative to the given pathname.
402 *
[0c6b92a]403 * @see https://reactrouter.com/v6/utils/resolve-path
[d565449]404 */
405export 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 */
429export declare function getPathContributingMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[]): T[];
430export declare function getResolveToMatches<T extends AgnosticRouteMatch = AgnosticRouteMatch>(matches: T[], v7_relativeSplatPath: boolean): string[];
431/**
432 * @private
433 */
434export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string, isPathRelative?: boolean): Path;
435/**
436 * @private
437 */
438export declare function getToPathname(to: To): string | undefined;
439/**
440 * @private
441 */
442export declare const joinPaths: (paths: string[]) => string;
443/**
444 * @private
445 */
446export declare const normalizePathname: (pathname: string) => string;
447/**
448 * @private
449 */
450export declare const normalizeSearch: (search: string) => string;
451/**
452 * @private
453 */
454export declare const normalizeHash: (hash: string) => string;
455export 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.
[0c6b92a]459 *
460 * @deprecated The `json` method is deprecated in favor of returning raw objects.
461 * This method will be removed in v7.
[d565449]462 */
463export declare const json: JsonFunction;
464export declare class DataWithResponseInit<D> {
465 type: string;
466 data: D;
467 init: ResponseInit | null;
468 constructor(data: D, init?: ResponseInit);
469}
470/**
471 * Create "responses" that contain `status`/`headers` without forcing
472 * serialization into an actual `Response` - used by Remix single fetch
473 */
474export declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
475export interface TrackedPromise extends Promise<any> {
476 _tracked?: boolean;
477 _data?: any;
478 _error?: any;
479}
480export declare class AbortedDeferredError extends Error {
481}
482export declare class DeferredData {
483 private pendingKeysSet;
484 private controller;
485 private abortPromise;
486 private unlistenAbortSignal;
487 private subscribers;
488 data: Record<string, unknown>;
489 init?: ResponseInit;
490 deferredKeys: string[];
491 constructor(data: Record<string, unknown>, responseInit?: ResponseInit);
492 private trackPromise;
493 private onSettle;
494 private emit;
495 subscribe(fn: (aborted: boolean, settledKey?: string) => void): () => boolean;
496 cancel(): void;
497 resolveData(signal: AbortSignal): Promise<boolean>;
498 get done(): boolean;
499 get unwrappedData(): {};
500 get pendingKeys(): string[];
501}
502export type DeferFunction = (data: Record<string, unknown>, init?: number | ResponseInit) => DeferredData;
[0c6b92a]503/**
504 * @deprecated The `defer` method is deprecated in favor of returning raw
505 * objects. This method will be removed in v7.
506 */
[d565449]507export declare const defer: DeferFunction;
508export type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
509/**
510 * A redirect response. Sets the status code and the `Location` header.
511 * Defaults to "302 Found".
512 */
513export declare const redirect: RedirectFunction;
514/**
515 * A redirect response that will force a document reload to the new location.
516 * Sets the status code and the `Location` header.
517 * Defaults to "302 Found".
518 */
519export declare const redirectDocument: RedirectFunction;
520/**
521 * A redirect response that will perform a `history.replaceState` instead of a
522 * `history.pushState` for client-side navigation redirects.
523 * Sets the status code and the `Location` header.
524 * Defaults to "302 Found".
525 */
526export declare const replace: RedirectFunction;
527export type ErrorResponse = {
528 status: number;
529 statusText: string;
530 data: any;
531};
532/**
533 * @private
534 * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
535 *
536 * We don't export the class for public use since it's an implementation
537 * detail, but we export the interface above so folks can build their own
538 * abstractions around instances via isRouteErrorResponse()
539 */
540export declare class ErrorResponseImpl implements ErrorResponse {
541 status: number;
542 statusText: string;
543 data: any;
544 private error?;
545 private internal;
546 constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
547}
548/**
549 * Check if the given error is an ErrorResponse generated from a 4xx/5xx
550 * Response thrown from an action/loader
551 */
552export declare function isRouteErrorResponse(error: any): error is ErrorResponse;
553export {};
Note: See TracBrowser for help on using the repository browser.